首页云计算 正文

使用python编写端口扫描器

2024-12-18 2 0条评论

前几天看了个讲使用Python扫描端口的教程,看了之后自己也写了个扫描端口的脚本。记录下来,方便自己以后回顾。

端口扫描端口效果图

python扫描器

 

python扫描器源代码

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 # -*- coding:utf8 -*- #!/usr/bin/python # Python:          2.7.8 # Platform:        Windows # Authro:          wucl # Program:         端口扫描 # History:         2015.6.1 import socket , time , thread socket . setdefaulttimeout ( 3 ) def socket_port ( ip , port ) :      “””     输入IP和端口号,扫描判断端口是否开放     “””      try :          if port >= 65535 :              print u ‘端口扫描结束’          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 ‘端口开放’              lock . release ( )          s . close ( )      except :          print u ‘端口扫描异常’ def ip_scan ( ip ) :      “””     输入IP,扫描IP的0-65534端口情况     “””      try :          print u ‘开始扫描 %s’ % ip          start_time = time . time ( )          for i in range ( 0 , 65534 ) :              thread . start_new_thread ( socket_port , ( ip , int ( i ) ) )          print u ‘扫描端口完成,总共用时 :%.2f’ % ( time . time ( ) start_time )          raw_input ( “Press Enter to Exit” )      except :          print u ‘扫描ip出错’          if __name__ == ‘__main__’ :      url = raw_input ( ‘Input the ip you want to scan:\n’ )      lock = thread . allocate_lock ( )      ip_scan ( url )

 

文章转载来自:trustauth.cn

文章版权及转载声明

本文作者:admin 网址:http://news.edns.com/post/217549.html 发布于 2024-12-18
文章转载或复制请以超链接形式并注明出处。

取消
微信二维码
微信二维码
支付宝二维码