Sunday, 14 August 2016

scan a ip using python script

Today i am going to create a script which will scan a given ip . Script will take the ip from user as argument .


just copy the bellow script as 1.py

import nmap
import sys
u=sys.argv[1:]
print u
y= u[0]
print y
ns=nmap.PortScanner()
print 'Welcome to ',ns.nmap_version(),'scan:'
print 'For the given ip , the follwoing ports are open __:\n\n'
ns.scan(y,'1-65000','-v')
print ns.csv()
print 'For the TCP porotocol the following ports are open__:'
print '\n\n',ns[y]['tcp'].keys()


While running this script you have to mention the ip as argument like bellow :

python2.7 1.py 192.168.145.132

You will get out like bellow __:

python2.7 1 192.168.145.132
['192.168.145.132']
192.168.145.132
Welcome to  (7, 12) scan:
For the given ip , the follwoing ports are open __:


host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe
192.168.145.132;anuj.com;PTR;tcp;22;ssh;open;;;syn-ack;;3;
192.168.145.132;anuj.com;PTR;tcp;514;shell;open;;;syn-ack;;3;
192.168.145.132;anuj.com;PTR;tcp;3306;mysql;open;;;syn-ack;;3;
192.168.145.132;anuj.com;PTR;tcp;9090;zeus-admin;open;;;syn-ack;;3;

For the TCP porotocol the following ports are open__:


[514, 3306, 22, 9090]


You can do lots of improvement with this script .

No comments:

Post a Comment

Popular Posts