Python--简单的端口扫描脚本
生活随笔
收集整理的這篇文章主要介紹了
Python--简单的端口扫描脚本
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author:1stPeakimport socket #導(dǎo)入socket模塊def common_port_scan(hosts,common_ports): #定義一個(gè)common_port_scan函數(shù)for j in hosts: #將hosts里的值賦給j,依次循環(huán)for i in common_ports: #將common_ports里的值賦給i,依次循環(huán)try: #異常處理s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #使用socket模塊s.connect((j,i)) #連接目標(biāo)端口#s.send(b'1stPeak') #向目標(biāo)發(fā)送數(shù)據(jù),可省略print("主機(jī)" + str(j) + " " + str(i) + " Open") #打印主機(jī),開放的端口信息except:pass #跳過關(guān)閉的端口信息#print("主機(jī)" + str(j) + " " + str(i) + " Close") #打印主機(jī),關(guān)閉的端口信息if __name__ == '__main__': #程序入口,當(dāng).py腳本運(yùn)行時(shí),if __name__ == '__main__':之下的代碼塊將會被運(yùn)行hosts=["10.10.19.100","192.168.1.1"] #創(chuàng)建一個(gè)host列表,用來查詢的主機(jī)ipcommon_ports = [21,22, 23, 80, 443, 445, 1433, 1521, 3306, 3389, 5432, 8080] #創(chuàng)建一個(gè)common_ports列表,用來查詢的主機(jī)端口common_port_scan(hosts, common_ports) #帶入?yún)?shù),調(diào)用common_port_scan()函數(shù)
總結(jié)
以上是生活随笔為你收集整理的Python--简单的端口扫描脚本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 醉翁亭记欧阳修翻译及原文
- 下一篇: 植树节的意义