Pyhton Scan Port Script code

Source: Internet
Author: User
Pyhton Scan Port Script code

#-*-Coding:utf8-*-#!/usr/bin/python# Program: Port scan import socket, time, Threadsocket.setdefaulttimeout (3) def Soc        Ket_port (Ip,port): "" "Enter IP and port number, scan to determine if port is open" "Try:if port>=65535:print U ' port scan end ' 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 () except:print u ' Port scan exception ' def ip_scan (IP): ' "" Input IP , scan IP 0-65534 port case "" "Try:print U ' start scan%s '% IP start_time=time.time () for I in range (0,65534)        : Thread.start_new_thread (Socket_port, (Ip,int (i))) Print U ' Scan port complete, total time:%.2f '% (Time.time ()-start_time) Raw_input ("Press Enter to Exit") except:print u ' scan IP error ' if __name__== ' __main__ ': url=raw_input (' input The IP want to scan:\n ') Lock=thread.allocate_lock () Ip_scan (URL)
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.