If all you're trying to do is enumerate a list of active IPs in given a range, why not use something that already exists for that purpose?
Checkout nmap:
sudo nmap -sn -n 10.11.1.0- -oG - | grep -i Host | cut -d" " -f2
The above command:
- nmap : scan the netwrok
- -sn + -sP : skip port scanning
- -n : skip reverse dns resolution
- 10.11.1.- : enumerate over 10.11.1.0
- the dash specifies to enumerate
- -oG - : convert the output for data processing
- grep -i Host : filter the output to only show enumerated values
- removes the header and footer of the nmap output
- cut -d" " -f2 : split the output into columns separated by spaces, then filter to only show the second column.
- shows just the ip addresses
Sample output
sudo nmap -sn -n 10.11.1.0.- -oG - | grep Host | cut -d" " -f2
# 10.11.1.0.1
# 10.11.1.0.100
# 10.11.1.0.101
# 10.11.1.0.103
# 10.11.1.0.106
# 10.11.1.0.169
# 10.11.1.0.108
Nmap supports scanning the current hosts' network range, as well any other network range.
If you need to execute this directly from python, use the subprocess module. https://docs.python.org/2/library/subprocess.html
More information about nmap:
https://linux.die.net/man/1/nmap
ipnum += 1?ipnumdoes.