OPS script: Python for bulk IP port scanning

Source: Internet
Author: User

OPS script: Python for bulk IP port scanning

Focus on network operation and maintenance, only send practical dry goods

Scan QR code to pay attention to the public

Today do not want to update, send an inventory, share a small piece of Python code to everyone, can achieve a simple batch port scanning, nonsense said, first on the code:

===========================================================

#-*-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: ')

===========================================================

Pre-run preparation work:

1, set the scan target, save as. xlsx execl table, in the following format:

Business Name IP Address Port number
Mailbox 1.1.1.1 25
Web 2.2.2.2 80
Remote Desktop 3.3.3.3 3389

2, install Python 3

3. External library required for installation: XLRD (table Read)

Install command: Pip install xlrd

Pro-Test effective, need to scan the host and port in the table to fill the line, applicable to a number of different host and port batch scanning, not applicable to a single IP 1-65535 port scan.

Focus on network operation and maintenance, only send practical dry goods

Scan QR code to pay attention to the public

OPS script: Python for bulk IP port scanning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.