当前位置 : 主页 > 编程语言 > python >

使用python实现nmap的UDP扫描

来源:互联网 收集:自由互联 发布时间:2022-06-18
import socket import time from scapy . all import * import optparse def tcpconnect ( host , port ): try : conn = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) conn . connect (( host , port )) print '[+]%d/tcp open' % ( port )


import socket
import time
from scapy.all import *
import optparse
def tcpconnect(host,port):
try:
conn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
conn.connect((host,port))
print '[+]%d/tcp open' % (port)
conn.close()
except:
pass
def udpconnect(host,port):
try:
rep = sr1(IP(dst=host)/UDP(dport=port),timeout=1,verbose=0)
time.sleep(1)
if rep.haslayer(ICMP()):
print '[-]%d/udp not open' % (port)
except:
print '[+]%d/udp open' % (port)

def portscan(host):
for port in range(1,1023):
udpconnect(host,port)
def main():
parser = optparse.OptionParser('usage\%\prog'+'-H <target host>')
parser.add_option('-H',dest=tgtHost,type='string',help='specify target host')
(option,args) = parser.parse_args()
host = options.tgthost
if host ==None:
print parser.usage
exit(0)
portscan(host)

if __name__ == '__main__':
main()



网友评论