• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

python端口扫描程序

python 水墨上仙 3084次浏览

这是一个简单的网络程序,可以用来扫描指定ip的常用端口

from socket import *
tgtHost=raw_input("What is the web address?: ")
tgtPorts=raw_input("What are the ports seperated by commas? or would you like to test all?: ")
def connScan(tgtHost, tgtPort):
    try:
        connSkt=socket(AF_INET, SOCK_STREAM)
        connSkt.settimeout(10)
        connSkt.connect((tgtHost, tgtPort))
        connSkt.settimeout(None)
        print("%d/tcp open"%tgtPort)
    except:
        print("%d/tcp closed"%tgtPort)
def portScan(tgtHost, tgtports):
    global tgtPorts
   
    if  tgtPorts=="yes" or tgtPorts=="ya" or tgtPorts=="sure" or tgtPorts=="ok" or tgtPorts=="y" or tgtPorts=="Y":
         tgtPorts=21, 22, 23, 25, 42, 43, 53, 67, 79, 80, 102, 110, 115, 119, 123, 135, 137, 143, 161, 179, 379, 389, 443, 445, 465, 636, 993, 995, 1026, 1080, 1090, 1433, 1434, 1521, 1677, 1701, 1720, 1723, 1900, 2409, 3101, 3306, 3389, 3390, 3535, 4321, 4664, 5190, 5500, 5631, 5632, 5900, 7070, 7100, 8000, 8080, 8799, 8880, 9100, 19430, 39720
   
   
    try:
        tgtIP=gethostbyname(tgtHost)
    except:
        print(" Cannot resolve '%s': Unknown host"%tgtHost)
        return
    try:
        tgtName=gethostbyaddr(tgtIP)
        print('\n Scan results for: %s' %tgtName)
    except:
        print('\n Scan results for: %s' %tgtIP)
    tgtPorts=tgtPorts.split(',')
    for port in tgtPorts:
        print('Scanning port %s'%port)
        connScan(tgtHost, int(port))
def main():
    portScan(tgtHost, tgtPorts)
if __name__=='__main__':
    main()
 


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明python端口扫描程序
喜欢 (0)
加载中……