使用Python編寫簡單的連接埠掃描器的執行個體分享【轉】

來源:互聯網
上載者:User

標籤:you   url   5.6   close   time   info   掃描器   orm   inpu   

 

轉自

使用Python編寫簡單的連接埠掃描器的執行個體分享_python_指令碼之家 http://www.jb51.net/article/76630.htm

 

 -*- coding:utf8 -*-#!/usr/bin/python# Python:     2.7.8# Platform:    Windows# Authro:     wucl# Program:     連接埠掃描# History:     2015.6.1  import socket, time, threadsocket.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)

 

 

使用Python編寫簡單的連接埠掃描器的執行個體分享【轉】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.