python socket 編寫普通埠掃瞄器

2021-10-05 15:44:13 字數 986 閱讀 5639

話不多說,上**(原理:利用socket套接字挨個連線目標埠,成功則輸出open,失敗則跳過)

from socket import *

import

time

def ping(

): ping

= os.system(

'ping'

) print(ping)

def handle(ip,port):

try:

client = socket(af_inet,sock_stream)

#client = socket() 預設tcp

client.settimeout(2)

#設定超時兩秒,超過就預設關閉

client.connect((ip,port))

print(f":open",end =

'\n'

) except:

# print(f"不開放")

pass

client.close(

)if __name__ ==

"__main__"

: ip =

"43.248.190.4"

list_port =

[20,21,22,23,25,53,80,81,102,109,110,119,135,137,138,139,161,443,554,1024,1080,1755,4000,5554,5632,8080]

#一般埠

for i in list_port:

print(f"正在掃瞄:",end =

'\r'

)#不斷重新整理當行

handle(ip,i)

**^蕾姆(* ̄(oo) ̄)鎮樓^**

Python Socket 程式設計

client import socket,sys if name main 處理引數 argv sys.argv if len argv 3 or len argv 2 and argv 1 print useage argv 0 sys.exit 0 host argv 1 server ip位址...

python socket程式設計

python 編寫server的步驟 1.第一步是建立socket物件。呼叫socket建構函式。如 socket socket.socket family,type family引數代表位址家族,可為af inet或af unix。af inet家族包括internet位址,af unix家族用於...

python socket程式設計

客戶端 author lenovo fromsocketimport host localhost port 2157 bufsize 1024 addr host,port tcpclient socket af inet,sock stream tcpclient.connect addr wh...