-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmap_scan.py
More file actions
33 lines (29 loc) · 1001 Bytes
/
nmap_scan.py
File metadata and controls
33 lines (29 loc) · 1001 Bytes
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
#!/usr/lib/python3.8
import nmap
import argparse
def nmapscan(tgthost,tgtport):
nmscan=nmap.PortScanner()
nmscan.scan(tgthost,tgtport)
try:
state=nmscan[tgthost]['tcp'][int(tgtport)]['state']
if state=='open':
print("[*]"+tgthost+" tcp "+tgtport+" "+state)
else:
print("port "+tgtport+" closed")
except Exception as e:
print("error occured as " +str(e))
def main():
parser=argparse.ArgumentParser()
parser.add_argument("-H",'--host',action='store',dest='tgthost',help='specify tareget host ip')
parser.add_argument('-p','--port',action='store',dest='tgtport',help='specify target port number')
args=parser.parse_args()
tgthost=args.tgthost
tgtport=args.tgtport
if not tgthost or tgtport:
print('[-]specfiy port and host ')
exit(0)
else:
print("scanning hsa begun")
nmapscan(tgthost,tgtport)
if __name__=='__main__':
main()