營運指令碼:python實現批量IP連接埠掃描

來源:互聯網
上載者:User

標籤: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連接埠掃描

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.