-
Notifications
You must be signed in to change notification settings - Fork 1
/
ip_generator.py
39 lines (35 loc) · 1.54 KB
/
ip_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import netaddr
from termcolor import cprint
#-----------This Function Check if its Single IP return as is
#-----------If its Range then Return List of IPs
def generate_range(input_ip):
generated_ips = netaddr.IPNetwork(input_ip)
ips = []
if(len(generated_ips)>1):
cprint("[+] Generating IP List",'green')
broadcast = raw_input("[?] Do you have broadcast IP to discard [y][n] : ")
if(broadcast == 'y' or broadcast == 'Y'):
for ip in generated_ips:
# Change from IP Object in format IPAddress('192.168.1.1') to String '192.168.1.1'
# Discarding Broadcast IP from Scan
if(ip == generated_ips.broadcast):
cprint("[-] Discarding Broadcast IP %s"%ip,'yellow')
continue
else:
ips.append(str(ip))
else:
for ip in generated_ips:
# Change from IP Object in format IPAddress('192.168.1.1') to String '192.168.1.1'
ips.append(str(ip))
network = raw_input("[?] Do you have network IP to discard [y][n] : ")
if(network == "y" or network == 'Y'):
ips.reverse()
network_IP = ips.pop()
ips.reverse()
cprint("[-] Discarding Network IP : %s"%network_IP,'yellow')
cprint("[+] %s IPs Ready to ping : "%str(len(ips)))
return ips # Return IP List
else:
cprint("[+] Single IP is Provided")
ips.append(input_ip)
return ips # Return List with Single IP