|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi folks,
how can i increment an ip adress in a speacial range? when start ip and stop ip is given ? ![]() with best regards chill4 |
|
#2
|
||||
|
||||
|
Something like this perhaps?
Code:
#!/usr/bin/env python
base_ip = "192.168.1"
start_oct = raw_input("Enter your start IP octet: ")
end_oct = raw_input("Enter your end IP octet: ")
for octet in xrange(int(start_oct), int(end_oct) + 1):
ip = base_ip + "." + str(octet)
print ip
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
||||
|
||||
|
Yet another way to do this
,Code:
#!/usr/bin/env python
def incrementAddress(address, to = 249, by = 1):
position = address.rindex('.') + 1
for each in xrange(1, to + 1, by):
yield address[:position] + str(each)
if __name__ == '__main__':
for IP in incrementAddress('123.123.123.1', 5):
print IP
Have fun, Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Increment IP an adress? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|