This article introduces Pyhton port scan script code
#-*-Coding: utf8 -*-#! /Usr/bin/python # Program: port scan import socket, time, threadsocket. setdefatimetimeout (3) def socket_port (ip, port): "Enter the IP address and port number, scan to determine whether the port is open" try: if port> = 65535: print U' port scan ended's = socket. socket (socket. AF_INET, socket. SOCK_STREAM) result = s. connect_ex (ip, port) if result = 0: lock. acquire () print ip, U': ', port, U' port open 'lock. release () s. close () failed t: print U' port scan exception 'Def ip_scan (ip): "Enter IP address, scan port 0-of IP address" "try: print U' start scanning % s' % ip start_time = time. time () for I in range (): thread. start_new_thread (socket_port, (ip, int (I) print U' port scan is complete, total Time: %. 2f '% (time. time ()-start_time) raw_input ("Press Enter to Exit") failed t: print U' ip scan error 'If _ name __= = '_ main __': url = raw_input ('input the ip you want to scan: \ n') lock = thread. allocate_lock () ip_scan (url)
The above is the script code for Pyhton Port Scanning. For more information, see other related articles in the first PHP community!