用Python3实现端口扫描器

Python3 端口扫描器

用python3 实现 connect syn udp扫描

话不多说,直接上代码

1.connect.py

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from socket import *

def portScanner(host,port):
    try:
        s = socket(AF_INET,SOCK_STREAM)
        s.connect((host,port))
        print('[+] %d open' % port)
        s.close()
    except:
        print('[-] %d close' % port)

def main_c(host,start,end):
    for p in range(start,end):
        portScanner(host,p)

if __name__ == '__main__':
    ip=input()
    start=int(input())
    end=int(input())
    main(ip,start,end)

2.udp.py

from scapy.all import *

def UdpScanner(ip,start,end):
    for port in range(start,end):
        a = sr1(IP(dst=ip) / UDP(dport=port), timeout=5, verbose=0)
        time.sleep(1)
        if a == None:
            print('[+] %d open' % port)
        else:
            print('[-] %d close' % port)
            pass
  1. scanner.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from socket import *
from scapy.all import *
from connent import *
from udp import *

def syn_scan(host,port):
    a=sr1(IP(dst=host)/TCP(dport=port),timeout=1,verbose=0)
    if a==None:
        print('[-] %d close' % port)
        pass
    else:
        if(a[TCP].flags)==18:
            print('[+] %d open' % port)

if __name__=='__main__':
        print('请输入要扫描的ip地址:')
        host=input()
        print('请输入要扫描的起始端口:')
        start=int(input())
        print('请输入要扫描的结束端口:')
        end=int(input())
        while(True):
            print('————————————————————————————————————————————————')
            print('请选择扫描类型:\n1.connect扫描\n2.syn扫描\n3.udp扫描\n4.按任意键退出')
            num=int(input())
            if num == 1:
                main_c(host, start, end)
            elif num == 2:
                print("开始扫描主机:%s..."%host)
                for p in range(start, end):
                    syn_scan(host, p)
            elif num == 3:
                UdpScanner(host,start,end)
            else:
                break

用法

创建connect.py和udp.py然后把我的代码复制到里面,最后创建scanner.py,把代码复制到其中,直接运行scanner.py即可。

最后

刚刚在创建虚拟机,等的时间有点长,用这个时间写下了这个博客,这个是我的一个网络编程实验,第一次写博客,有点混乱,代码放在这里 还请大家斧正。

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
支持多线程快速扫描 支持网段扫描: ScanPort.py 支持自定义网段扫描: ScanPort.py 192.168.2 支持自定义子网段扫描: ScanPort.py 192.168.3.100 192.168.3.120 支持Web端口自动显示链接: C:\>ScanPort.py Scanning [192.168.200.1]-[192.168.200.254] Total 254 ip(s)... 192.168.200.1 80 web http://192.168.200.1 192.168.200.81 80 web http://192.168.200.81 192.168.200.81 443 web https://192.168.200.81 192.168.200.99 80 web http://192.168.200.99 192.168.200.99 443 web https://192.168.200.99 192.168.200.115 80 web http://192.168.200.115 192.168.200.115 443 web https://192.168.200.115 192.168.200.123 80 web http://192.168.200.123 192.168.200.123 443 web https://192.168.200.123 192.168.200.130 80 web http://192.168.200.130 192.168.200.130 443 web https://192.168.200.130 192.168.200.133 80 web http://192.168.200.133 192.168.200.133 443 web https://192.168.200.133 192.168.200.144 80 web http://192.168.200.144 192.168.200.144 443 web https://192.168.200.144 192.168.200.151 8080 web http://192.168.200.151 192.168.200.160 443 web https://192.168.200.160 192.168.200.160 80 web http://192.168.200.160 192.168.200.163 80 web http://192.168.200.163 192.168.200.163 443 web https://192.168.200.163 192.168.200.163 1080 Proxy 192.168.200.168 80 web http://192.168.200.168 192.168.200.168 443 web https://192.168.200.168 192.168.200.168 1080 Proxy 192.168.200.173 8080 web http://192.168.200.173 192.168.200.173 443 web https://192.168.200.173 192.168.200.181 80 web http://192.168.200.181 192.168.200.181 443 web https://192.168.200.181 192.168.200.180 80 web http://192.168.200.180 192.168.200.180 443 web https://192.168.200.180 192.168.200.192 80 web http://192.168.200.192 192.168.200.192 443 web https://192.168.200.192 All RUN TIME : 97.0510001183s

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值