jeudi 21 septembre 2017

If, elif, print based on three variables of an input in python

HELP! I'm stuck with this python script. So basically I want my program to run the first part of the code when there is an input from recieved from the user for all three variables.

I was trying to basically have if there is . in a, dash in b, and . in c then run these print statements. Else do what's below. NOTE: The first code has different print statements from the others. I want it to run the first part of the code based on a,b,c all having an input. Appreciate the help

code

a = raw_input("Enter ip address: ")
b = raw_input("Enter range: ")
c = raw_input("Enter network: ")

#should print ip adress, range, and network combined 
if '.' in a + '-' in b + '.' in c:
ips = b.split('-')
print 'config firewall address\n','edit "ip-' + str(a) + '"'
print 'set subnet ' + str(a) + '/32'
print 'next'
print 'edit "ip-' + str(b) + '"'
print ('set type iprange')
print ('set start-ip '+ips[0])
print 'set end-ip '+ips[1]
print 'next'
print 'edit "net-' + str(c) + '"'
print 'set subnet ' + str(c) + ''
print 'next'
print 'end'

output

The rest of the code runs based on user input.

#SHOULD print ip adress, range, and network combined
Enter ip address: 10.203.1.10
Enter range: 10.228.50.88-10.228.50.91
Enter network: 172.27.0.0/16
config firewall address
edit "ip-10.203.1.10"
set subnet 10.203.1.10/32
next
end

I don't want the last output to be like that. This is my desired output.

Enter ip address: 10.203.1.10
Enter range: 10.228.50.88-10.228.50.91
Enter network: 172.27.0.0/16
config firewall address
edit "ip-10.203.1.10"
set subnet 10.203.1.10/32
next
edit "ip-10.228.50.88-10.228.50.91"
set type iprange
set start-ip 10.228.50.88
set end-ip 10.228.50.91
next
edit "net-172.27.0.0/16"
set subnet 172.27.0.0/16
next
end

What do I need to do?

Aucun commentaire:

Enregistrer un commentaire