Hi, i am very new with python coding using version 2.7, i am trying to create a network scanner using nmap module.Need help to improve my scanner such that it should scan the network or ip_range and detect all operating systems with accuracy of 100% and should provide a count for how many os are on my network. for example os and count: windows 7,10, windows xp,0, windows 10,12 linux,13.
Further would want the output to be saved both to text file and screen for log purposes. Find my script below
import nmap
print """+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| WELCOME TO MY NETWORK SCANNER |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"""
###########################################
loop = 1
choice = 0
###########################################
nmScan = nmap.PortScanner()
text_file = open('ww.txt', 'w') #file where output is stored
def nmapScan(hosts, arguments="-O"):
nmScan = nmap.PortScanner()
hosts = raw_input('Enter IP address : ') #ip address or range input
nmScan.scan(hosts, arguments="-O")
if 'osmatch' in nmScan[hosts]:
for osmatch in nmScan[hosts]['osmatch']:
text_file.write('OsMatch.name : {0}'.format(osmatch['name'])) #output saved to text file
text_file.write('OsMatch.accuracy : {0}'.format(osmatch['accuracy']))
print('OsMatch.name : {0}'.format(osmatch['name'])) #output displayed on screen
print('OsMatch.accuracy : {0}'.format(osmatch['accuracy']))
print('out results saved to file....................')
while loop == 1:
print "Choose Network Scanning Options Below"
print "1) Scan Network"
print "2) Quit the program"
choice = input ("choose your option :")
if choice == 1:
nmapScan('hosts', arguments="-O")
if choice == 2:
loop = 0
print('!!!! done program closed !!!!')
Further would want the output to be saved both to text file and screen for log purposes. Find my script below
import nmap
print """+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| WELCOME TO MY NETWORK SCANNER |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"""
###########################################
loop = 1
choice = 0
###########################################
nmScan = nmap.PortScanner()
text_file = open('ww.txt', 'w') #file where output is stored
def nmapScan(hosts, arguments="-O"):
nmScan = nmap.PortScanner()
hosts = raw_input('Enter IP address : ') #ip address or range input
nmScan.scan(hosts, arguments="-O")
if 'osmatch' in nmScan[hosts]:
for osmatch in nmScan[hosts]['osmatch']:
text_file.write('OsMatch.name : {0}'.format(osmatch['name'])) #output saved to text file
text_file.write('OsMatch.accuracy : {0}'.format(osmatch['accuracy']))
print('OsMatch.name : {0}'.format(osmatch['name'])) #output displayed on screen
print('OsMatch.accuracy : {0}'.format(osmatch['accuracy']))
print('out results saved to file....................')
while loop == 1:
print "Choose Network Scanning Options Below"
print "1) Scan Network"
print "2) Quit the program"
choice = input ("choose your option :")
if choice == 1:
nmapScan('hosts', arguments="-O")
if choice == 2:
loop = 0
print('!!!! done program closed !!!!')