码迷,mamicode.com
首页 > 其他好文 > 详细

通过UDP探测端到端MTU

时间:2017-06-24 09:59:14      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:端到端   soc   help   ann   exce   sock   prot   err   rip   

P_MTU_D(Path MTU Discovery)

socket的UDP功能,去发现端到端MTU

#!/usr/bin/env python3
#-*- encoding:utf8 -*-
#Used UDP to learn the MTU of the end_to_end PATH_MTU

import IN,argparse,socket

if not hasattr(IN,IP_MTU):
    raise RuntimeError(cannot perform MTU discovery on this combination)

def send_big_datagram(host,port):
    sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    sock.setsockopt(socket.IPPROTO_IP,IN.IP_MTU_DISCOVER,IN.IP_PMTUDISC_DO)
    sock.connect((host,port))
    try:
        sock.send(b#*65535)
    except socket.error:
        print("also,the datagram did not make it")
        max_mtu = sock.getsockopt(socket.IPPROTO_IP,IN.IP_MTU)
        print(Actual MTU:{}.format(max_mtu))

if __name__ == __main__:
    parser = argparse.ArgumentParser(description=Send UDP Packet to Get PATH_MTU)
    parser.add_argument(host,help=the target host)
    parser.add_argument(-p,metavar=port,type=int,default=1060,help=UDP port((default 1060))
    args = parser.parse_args()
    send_big_datagram(args.host,args.p)

 

通过UDP探测端到端MTU

标签:端到端   soc   help   ann   exce   sock   prot   err   rip   

原文地址:http://www.cnblogs.com/alben-cisco/p/7072158.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!