如何用Python代码实现基于nmap的UDP端口扫描功能?

2026-05-26 12:031阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计206个文字,预计阅读时间需要1分钟。

如何用Python代码实现基于nmap的UDP端口扫描功能?

pythonimport socketimport timefrom scapy.all import *import optparse

def tcpconnect(host, port): try: conn=socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((host, port)) print(f[+] {port}/tcp open) except: pass


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()



如何用Python代码实现基于nmap的UDP端口扫描功能?

标签:UDP扫描imp

本文共计206个文字,预计阅读时间需要1分钟。

如何用Python代码实现基于nmap的UDP端口扫描功能?

pythonimport socketimport timefrom scapy.all import *import optparse

def tcpconnect(host, port): try: conn=socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((host, port)) print(f[+] {port}/tcp open) except: pass


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()



如何用Python代码实现基于nmap的UDP端口扫描功能?

标签:UDP扫描imp