-
Notifications
You must be signed in to change notification settings - Fork 3
/
nmap_helper.py
48 lines (38 loc) · 1.09 KB
/
nmap_helper.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
39
40
41
42
43
44
45
46
47
REPORT = "Nmap scan report for "
# Example of what we're looking for in get_ip and get_hostname
# Nmap scan report for 127.0.0.0
# Nmap scan report for something.something.someting.pwn (127.0.0.1)
def get_ip(data):
for line in data.splitlines():
if REPORT in line:
predicate = line.split(REPORT)[1]
if "(" in predicate:
return predicate.split(' ')[1][1:-1]
else:
return predicate
def get_hostname(data):
for line in data.splitlines():
if REPORT in line:
predicate = line.split(REPORT)[1]
if "(" in predicate:
return predicate.split(' ')[0]
else:
return predicate
def get_ports(data):
ports = []
for line in data.split('\n'):
try:
x = int(line.split('/')[0])
except:
continue
if int(x) > 0:
ports.append(x) # yup, it's a port alright
return ports
#return [1,2,3]
def get_country(ip):
return "fake"
if __name__ == "__main__":
data = open("sample-output.txt").read()
print("ip: "+get_ip(data))
print("hostname: "+get_hostname(data))
print("ports: "+str(get_ports(data)))