-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhichDOS.py
43 lines (32 loc) · 1.03 KB
/
whichDOS.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
#!/usr/bin/python3
#Coding: UTF-8
# Author: Víctor García (Qv1ko)
import re, sys, subprocess
if len(sys.argv) != 2:
print("\n\n[!] ERROR - Write syntax correctly -> python3 " + sys.argv[0] + " <ip-address>\n")
sys.exit(1)
def get_ttl(ip_address):
proc = subprocess.Popen(["/usr/bin/ping -c 1 %s" % ip_address, ""], stdout=subprocess.PIPE, shell=True)
(out,err) = proc.communicate()
out = out.split()
out = out[12].decode('utf-8')
ttl_value = re.findall(r"\d{1,3}", out)[0]
return ttl_value
def get_os(ttl):
ttl = int(ttl)
if ttl >= 54 and ttl <= 74:
# Linux, FreeBSD and MacOS default TTL -> 64
return "Linux / FreeBSD / MacOS"
elif ttl >= 118 and ttl <= 138:
# Windows default TTL -> 128
return "Microsoft Windows"
elif ttl >= 245 and ttl <= 255:
# Solaris, OpenBSD default TTL -> 255
return "OpenBSD / Solaris"
else:
return "Default TTL not found"
if __name__ == '__main__':
ip_address = sys.argv[1]
ttl = get_ttl(ip_address)
os_name = get_os(ttl)
print("\n%s (ttl -> %s): %s\n" % (ip_address, ttl, os_name))