2016-02-05 126 views
-1

我是一名新的Python學習者。任何人都可以使用基本腳本來掃描http和https端口,並在用戶輸入子網(例如192.168.1.0/24)後返回IP地址嗎?感謝您的幫助python中的端口掃描

+0

歡迎StackOverflow上,Python_Learner!不幸的是,你對這個網站的問題太廣泛了。我們很樂意幫助您解決編程時遇到的具體問題,但您必須先嚐試併發布更多詳細信息。請參閱「[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)」以獲取更多信息。 – fusion3k

回答

1

後來,我用Python寫了一個TCP端口掃描器。它很好地工作,並且易於配置。您輸入IP或互聯網地址,並輸出您掃描的端口。它在Python 2.7的50行中。玩的開心!

#!/usr/bin/env python 
# PIES v1.1 
# SYZYGY-DEV333 
# Simple TCP port scanner in Python 
# Apache Version 2 

from socket import * 
import sys, time 
from datetime import datetime 

host = '' 
max_port = 5000 
min_port = 1 

def scan_host(host, port, r_code = 1): 
    try: 
     s = socket(AF_INET, SOCK_STREAM) 
     code = s.connect_ex((host, port)) 
     if code == 0: 
      r_code = code 
     s.close() 
    except Exception, e: 
     pass 
    return r_code 

try: 
    host = raw_input(">> Enter Target Host Address: ") 
except KeyboardInterrupt: 
    print("\n\n>> User Requested An Interrupt.") 
    print(">> Application Shutting Down.") 
    sys.exit(1) 

hostip = gethostbyname(host) 
print("\n>> Host: %s IP: %s" % (host, hostip)) 
print(">> Scanning Started At %s...\n" % (time.strftime("%H:%M:%S"))) 
start_time = datetime.now() 

for port in range(min_port, max_port): 
    try: 
     response = scan_host(host, port) 
     if response == 0: 
      print(">> Port %d: Open" % (port)) 
    except Exception, e: 
     pass 

stop_time = datetime.now() 
total_time_duration = stop_time - start_time 
print("\n>> Scanning Finsihed At %s ..." % (time.strftime("%H:%M:%S"))) 
print(">> Scanning Duration: %s ..." % (total_time_duration)) 
print(">> Have a nice day!") 

見我的項目在這裏:https://github.com/SYZYGY-DEV333/PIES