1 Star 0 Fork 229

hello-tom/project_25500701

forked from mktime/python-learn 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
scan.py 1008 Bytes
一键复制 编辑 原始数据 按行查看 历史
内部项目 提交于 2021-12-28 22:27 . 增加推荐项目
from socket import *
import threading
import queue
import sys
threads = []
q = queue.Queue()
for i in range(1, 65535):
q.put(i)
def portScanner(host, q):
while True:
port = -1
try:
port = q.get_nowait()
except queue.Empty:
print("finished")
break
#print(port)
if port == -1:
break
try:
s = socket(AF_INET,SOCK_STREAM)
s.connect((host,port))
print('[+] %d open' % port)
s.close()
except:
pass
def main():
setdefaulttimeout(2)
if len(sys.argv) != 2:
print('usage: python3 scan.py 1.1.1.1')
sys.exit()
host = sys.argv[1].strip()
thread_num = 100
for i in range(thread_num):
t = threading.Thread(target=portScanner, args=(host, q))
threads.append(t)
t.start()
for t in threads:
t.join()
print('[*] The scan is complete!')
if __name__ == '__main__':
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hello-tom/python-learn.git
git@gitee.com:hello-tom/python-learn.git
hello-tom
python-learn
project_25500701
master

搜索帮助