栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python-UDP协议

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python-UDP协议

python-UDP协议 UDP协议:

        python中基于udp协议的客户端与服务端通信简单过程实现

  udp协议的一些特点(与tcp协议的比较)

       利用socketserver模块实现udp传输协议的并发通信

代码:
import optparse
from scapy.all import *
from scapy.layers.inet import IP, TCP


def Scan(ip):
    try:
        dport = random.randint(1, 65535)
        packet = IP(dst=ip) / TCP(dport=80)
        respone = sr1(packet, timeout=1.0, verbose=0)
        if respone:
            if int(respone[IP].proto) == 1:
                time.sleep(0.5)
                print(ip + ' ' + "is up")
            else:
                print(ip + ' ' + "is down")
        else:
            print(ip + ' ' + "is down")
    except:
        pass


def main():
    parser = optparse.OptionParser("Usage: %prog -i ")
    parser.add_option("-i", '--ip', type="string", dest="targetIP", help="specify the IP address")
    options, args = parser.parse_args()
    if '-' in options.targetIP:
        for i in range(int(options.targetIP.split('-')[0].split('.')[3]), int(options.targetIP.split('-')[1]) + 1):
            Scan(options.targetIP.split('.')[0] + '.' + options.targetIP.split('.')[1] + '.' +
                 options.targetIP.split('.')[2] + '.' + str(i))
    else:
        Scan(options.targetIP)


if __name__ == '__main__':
    main()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/657473.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号