梅林固件设置虚拟内存
让梅林R6400支持sftp协议

p2p内网穿透技术-udp打洞

妙音 posted @ 2018年11月25日 16:47 in network with tags p2p udp vps , 2050 阅读
 
 
在公司如何访问家里的电脑?实现方法有很多,其它p2p传输文件最快,能否实现?
 

udp打洞原理

 
假设有两台分别处于各自的私有网络中的主机:A和B;N1和N2是两个网络的NAT设备,分别拥有IP地址P1和P2;S是一个使用了一个众所周知的、从全球任何地方都能访问得到的IP地址的公共服务器

步骤一:A和B分别和S建立UDP连接;NAT设备N1和N2创建UDP转换状态并分配临时的外部端口号

步骤二:S检查UDP包,看A和B的端口是否是正在被使用的(否则的话N1和N2应该是应用了端口随机分配,这会让路由验证变得更麻烦)

步骤三:如果端口不是随机化的,那么A和B各自选择端口X和Y,并告知S。S会让A发送UDP包到P2:Y,让B发送UDP包到P1:X

步骤四:A和B通过转换好的IP地址和端口直接联系到对方的NAT设备;
 
 
 

udp打洞成功前提条件--非对称NAT

 
完全圆锥型NAT: 无条件转发
 
受限圆锥型NAT:  忽略掉其它主机的数据包(要求来源ip一直)
 
端口受限圆锥型NAT: 更进一步地要求源端口(上例中是 2727)必须跟之前发出的数据包的目的端口一致(要求来源ip和端口)
 
对称NAT: 丢弃报文,拒绝转发(每次连接端口会变)
 
对称NAT理论上可以使用端口预测,但是基本上用不了。现在国内几个宽带运行商都是使用对称NAT,所以udp打洞不可行。
 
记得之前上学的时候p2p共享软件很多,后来都销声匿迹,应该是被管控了。
 

socat测试udp打洞

 
下面是socat打洞的例子,试过在公司与家里之间打洞,用不了被现实了
 
https://blog.lilydjwg.me/2012/8/28/udp-hole-punching-experiment.35350.html
 

frp测试udp打洞

 
frp采用xtcp协议,试过同样用不了。stcp可以用,但是不是p2p,要经过中间转发。
 

检查nat类型?

 
#python直接用pynat包
pip install pynat
 

pynat

 
C:\Users\wyq>pynat
Network type: Symmetric NAT   #对称nat
Internal address: 192.168.50.169:54320
External address: xxx.xxx.xxx.xxx:61195
 

 内网穿透可行方法

方法   描述  实现条件 实际是否可行
p2p      udp打洞 非对称nat 不可行。宽带基本都是对称nat。除非在自己公网ip上提供p2p穿透
ddns 路由器使用有公网ip 宽带提供了公网ip 不可行。路由器基本没有公网ip
端口转发 将端口映射到公网ip 需要公网ip 可行
vpn      要求有公网ip节点,运行vpn服务端 需要公网ip 可行

 

参考来源

 

 

Avatar_small
charliewhite 说:
2020年10月20日 16:44

Essay typist at dzone - Looking for Assignment Writing Services UK? Here We at TreatAssignmentHelp offering a wide range of Academic Writing Services & Assignment Help with Essay Writing Services UK, Assignment Writing Help Services, Assignment Help Wales UK for students. High qualified writers, 24/ 7 support, and complete privacy guarantee. Call or WhatsApp on +44 7520644027 to hire the best suitable academic writer for your subject. We promise to deliver projects before the deadline and without plagiarism. For More Services: Ella Phillips on threadless

Avatar_small
helphub 说:
2020年11月19日 01:14

Whether it is popular games like Baccarat, Slots, Blackjack, Roulette and Dragon Tiger etc. สล็อต

Avatar_small
buy soma 500 说:
2020年11月19日 16:53

I wish more authors of this type of content would take the time you did to research and write so well. I am very impressed with your vision and insight. 먹튀검증

Avatar_small
sagame66 说:
2020年11月21日 14:59

I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think. sagame66

Avatar_small
buy soma 500 说:
2020年11月23日 20:06

I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. okdermo

Avatar_small
더킹카지노 추천 说:
2020年12月08日 16:48

Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. 더킹카지노 추천

Avatar_small
no excuses runner 说:
2020年12月08日 21:06

This is my first time i visit here. I found such a substantial number of interesting stuff in your blog especially its examination. Really its inconceivable article. Keep it up. find here

Avatar_small
안전놀이터 说:
2020年12月09日 16:17

Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. 안전놀이터

Avatar_small
pretty gaming 说:
2020年12月14日 19:14

This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. pretty gaming

Avatar_small
vape pen dry herb va 说:
2020年12月16日 16:13

Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. vape pen dry herb vaporizer

Avatar_small
no excuses runner 说:
2021年1月03日 18:39

Incredible articles and awesome design. Your blog entry merits the greater part of the positive input it"s been getting. custom patches

Avatar_small
no excuses runner 说:
2021年1月04日 20:30

I wish more authors of this type of content would take the time you did to research and write so well. I am very impressed with your vision and insight. see it here


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter