资源简介
课程设计,制作基于socket库的端口扫描器程序,分别针对TCP和UDP
代码片段和文件信息
import optparse;
import nmap
from socket import *;
from threading import *;
screenLock = Semaphore(value=4) #处理多线程问题,使用screenLock.acquire()执行加锁
‘‘‘
使用socket进行端口扫描,通过socket(AF_INETSOCK_STREAM)指定基于IPv4网络,tcp连接,
使用connect去进行连接,成功则为端口开放,失败则为端口关闭。
‘‘‘
def tconnScan(tHosttPort):
try:
connSkt = socket(AF_INETSOCK_STREAM)
connSkt.connect((tHosttPort))
screenLock.acquire()
print(“[+]%d/tcp open“% tPort)
screenLock.release()
connSkt.close()
except:
screenLock.acquire()
print(“[-]%d/tcp closed“% tPort)
screenLock.release()
finally:
exit(0)
def tportScan(tHosttPorts):
try:
tIP = gethostbyname(tHost)
except:
print(“[-] Cannot resolve ‘%s‘: Unknown host“%
- 上一篇:iOS自动化测试自动允许弹框
- 下一篇:Python爬虫爬取百度百科词条源码
评论
共有 条评论