最近為了獲取虛擬機器埠開放情況,寫了乙個簡單指令碼來檢視。共享給大家。下面的**在python2種測試通過
說明:concurrent是python 3.2 引入的乙個庫,在python2中使用需要手動安裝一下: pip install futures
from concurrent import futures
import socket
import threading
import time
socket.setdefaulttimeout(3)
defscan_port
(ip, port):
try:
s = socket.socket(socket.af_inet, socket.sock_stream)
result=s.connect_ex((ip,port))
if(result==0):
print ip,":",port,"open"
s.close()
except:
print
"scan exception!"
if __name__== "__main__":
ip = "127.0.0.1"
t = time.time()
with futures.threadpoolexecutor(max_workers=100) as executor:
future_to_port =
for future in futures.as_completed(future_to_port):
future.result()
total_time = time.time() - t
print
"total time:%f" % total_time
~
root@centos:~# python scan.py
127.0
.0.1 : 22
open
127.0
.0.1 : 80
open
127.0
.0.1 : 443
open
127.0
.0.1 : 3306
open
127.0
.0.1 : 4200
open
127.0
.0.1 : 8001
open
total time:20.943239
python實現埠掃瞄
一 import socket import multiprocessing def ports ports service 獲取常用埠對應的服務名稱 for port in list range 1,100 143,145,113,443,445,3389,8080 try ports servi...
python指令碼 埠掃瞄
記錄在b站學習的知識 利用tcp原理,通過編寫python指令碼,來檢測某個主機的埠開放情況,下面介紹兩種掃瞄,syn掃瞄和fin掃瞄 實驗環境 準備工作 展示from scapy.layers.inet import ip,tcp from scapy.sendrecv import sr syn...
Python 內網埠掃瞄
import socket,threadpool ports def scan poort port ip 192.168.1.131 s socket.socket socket.af inet,socket.sock stream socket.socket 建立socket 例項 af ine...