Python Forum

Full Version: Need Help To Improve my Network Scanner
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 !!!!')
(Oct-20-2017, 04:18 PM)cybrary Wrote: [ -> ]i am very new with python coding using version 2.7

Why are you using Python 2.7 and not the latest 3.6.3?
Hi using python 2.7 because its the only one available, but will try to install the latest version. Would however appreciate your help on this code or a book that can help me improve my code skills.
In order to get any help, repost with your code in code tags.
See BBcode help for more info.