標籤:pen class width 格式 amp ota == 技術 net
營運指令碼:python實現批量IP連接埠掃描
專註網路營運,只發實用乾貨
掃描二維碼關注公眾
今天不想更新,發一篇存貨,分享一小段python代碼給大家,能實現簡單的批量連接埠掃描,廢話不多說,先上代碼:
===========================================================
# -*- coding: utf-8 -*-
import socket
import time
import xlrd
import threading
hostfile = xlrd.open_workbook(‘port_scan.xlsx‘) #調用掃描目標表格檔案
table_list = hostfile.sheet_by_index(0) #讀取表格中的第一個sheet頁
hang = table_list.nrows
lie = table_list.ncols
print ("Total hosts: %d" % (hang-1))
def scan(deviceID,hostname,hostip,PORT):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5) #逾時時間
s.connect((hostip,PORT))
print (‘%d_%s %s %s OPEN‘ % (deviceID,hostname,hostip,PORT))
except:
print (‘%d_%s %s %s CLOSE‘ % (deviceID,hostname,hostip,PORT))
s.close()
for deviceID in range(1, hang):
hostname = table_list.cell(deviceID, 0).value
hostip = table_list.cell(deviceID, 1).value
PORT = int(table_list.cell(deviceID, 2).value)
threading.Thread(target=scan,args=(deviceID,hostname,hostip,PORT)).start()
time.sleep(0.2) #間隔時間可以自己調
time.sleep(10)
input(‘Enter Quit:‘)
===========================================================
運行前準備工作:
1,制定掃描目標,儲存為 .xlsx 的execl表格,格式如下:
| 業務名稱 |
IP地址 |
連接埠號碼 |
| 郵箱 |
1.1.1.1 |
25 |
| WEB |
2.2.2.2 |
80 |
| 遠端桌面 |
3.3.3.3 |
3389 |
2,安裝python 3
3,需要安裝的外部庫:xlrd(表格讀取)
安裝命令:pip install xlrd
親測有效,需要掃描的主機和連接埠在表格中填好就行,適用於多個不同主機和連接埠的批量掃描,不適用單個IP的1-65535連接埠掃描。
專註網路營運,只發實用乾貨
掃描二維碼關注公眾
營運指令碼:python實現批量IP連接埠掃描