"""
项目名称:端口探测扫描
作者:白
版本:1.0
注:这里以mysql 3306 为例,port 换成80 也可以
"""
#引入线程和socket的模块
import threading import socket routers = [] #用于保存探测结果 lock = threading.Lock() #构造一把锁 def main(): local_ip = socket.gethostbyname_ex(socket.gethostname()) all_threads = [] for ip in local_ip[ 2 ]: for i in range ( 1 , 255 ): array = ip.split( "." ) #把IP以点号做分割 array[ 3 ] = str (i) new_ip = '.' .join(array) #在把列表的内容转换成IP t = threading.Thread(target = check_ip,args = (new_ip,)) #构造线程池 t.start() #开启线程 all_threads.append(t) for t in all_threads: t.join() #保持队列 def check_ip(new_ip): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) #创建套接字 s.settimeout( 1 ) PORT = 3306 result = s.connect_ex((new_ip,PORT)) if result = = 0 : lock.acquire() # 获取锁 print (new_ip.ljust( 15 ), 'port %s is open' % PORT) lock.release() # 锁释放 print ( 'search for router,please wait......' ) if __name__ = = '__main__' : main() |
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦