使用python掃瞄伺服器開放的埠和服務

2021-10-14 01:50:00 字數 1502 閱讀 6837

在安裝有nmap和python3的centos等linux伺服器上直接執行執行

須在同目錄下建立乙個名為ip.txt的檔案

在txt檔案中放入需要掃瞄的ip

def open_post1(self): # 構建open的ip和埠

sport = "-p1-1000 "

print("掃瞄:"+self.ip)

ord_1 = "nmap -t5 -ss "+sport+self.ip

ord_2_1 = "nmap -t4 -sv -p"

lines = os.popen(ord_1).readlines()

os.popen(ord_1).close()

for line in lines:

a1 = re.findall("open", line)

try:

if str(a1[0]) == "open":

port_open = re.findall(r"(.*?)/", line)

port_open = str(port_open[0])

ord_2_1 = ord_2_1+port_open+","

with open("opened.txt", "a") as f:

f.write(self.ip+":"+line)

except:

a = 1

ord_2_1 = ord_2_1[:-1]

ord_2 = ord_2_1+" -a "+self.ip

return ord_2

def open_post2(self,req_sc): # 檢視安全態勢

req_err = re.findall(r"-sv -(.*?)-",req_sc)

if req_err[0] == " ":

print("未發現開放埠")

else:

os.system(req_sc)

print("-----------------------我是分界線-----------------------")

n_ip = open("ip.txt", 'r').readlines()

for s in n_ip:

sc_ip = shcip(s)

req_sc = sc_ip.open_post1()

print("查詢開放埠範圍:"+req_sc)

伺服器端口開放

查詢埠號80 是否開啟 firewall cmd query port 80 tcp 永久開放80埠號 firewall cmd permanent zone public add port 80 tcp 移除80埠號 firewall cmd permanent zone public remov...

檢測伺服器開放埠

1.使用nmap檢測開放埠,可檢測遠端伺服器 root localhost nmap localhost starting nmap 6.40 at 2020 06 09 01 40 cst nmap scan report for localhost 127.0.0.1 host is up 0....

python 連線伺服器 Python伺服器連線

我想你用python編寫乙個客戶端,把資料報傳送到tcp伺服器。我不知道伺服器實現,但它總是返回這樣乙個men 例如在nc server 4444之後 make your choice 1 test1 2 test2 3 insert two numbers 4 test4 5 test5 6 te...