通过UDP探测端到端MTU
Posted alben-xue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过UDP探测端到端MTU相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章