Python implements the TCP port scan Tool

Source: Internet
Author: User

Tag:python    Scan Tool    

[[email protected] ~]# cat  portscan.py #!/usr/bin/env python# -*-  coding:utf-8 -*-import socket# instantiation of an object S = socket.socket ()   #循环遍历你自定义的端口范围   For port in range (1,65535):   #使用python的异常处理 to determine the behavior after a program error   try:     print  "[+] attempting to connect to 127.0.0.1: "  +  STR (port)      #客户端对服务器端进行连接, the format of the general address is a tuple (hostname,port) and returns a socket.error error if there is an error in the connection.     s.connect ((' 127.0.0.1 ',  port))      #发送tcp数据      s.send (' Fuweichao ')      #接受TCP套接字的数据. The data is returned as a string, bufsize specifies the maximum amount of data to receive     BANNER = S.RECV (1024x768)     if  banner:      print  "[+] port "  + str (Port)  +   " open: \n"  + banner    s.close ()   except: pass 

Python knowledge points used: Socket programming, exception handling, for loop traversal, if judgment.

This article from "Shangwei Super" blog, declined reprint!

Python implements the TCP port scan Tool

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.