我正在尝试使用teredo interface构建基于UDP的p2p c#应用程序,我设法使用以下命令在我的Windows 7操作系统上启用此接口:
netsh interface teredo>set state client teredo.remlab.net 60 23456
并在激活后打印出netsh interface teredo>show state
命令:
Type : client
Server Name : teredo.remlab.net
Client Refresh Interval : 60 seconds
Client Port : 23456
State : qualified
Client Type : teredo client
Network : unmanaged
NAT : symmetric (port)
NAT Special Behaviour : UPNP: Yes, PortPreserving: No
Local Mapping : 192.168.8.100:23456
External NAT Mapping : 188.247.74.161:37457
使用打印的ping -t -6 www.google.com
命令ping:基于google ipv6的主机:
Pinging www.google.com [2a00:1450:4007:807::2004] with 32 bytes of data:
Request timed out.
Reply from 2a00:1450:4007:807::2004: time=123ms
Reply from 2a00:1450:4007:807::2004: time=121ms
Reply from 2a00:1450:4007:807::2004: time=127ms
现在我的问题是:这是否足以说我可以使用teredo从我的Lan外部访问?如果是的话......我的外部终点会让其他同行访问我吗?
这是我的c#代码,用于收听teredo界面(如果出现问题,请更正我):
UdpClient Client = new UdpClient(23456, AddressFamily.InterNetworkV6);
Client.AllowNatTraversal(true);
Client.Client.SetIPProtectionLevel(IPProtectionLevel.Unrestricted);
int counter = 0;
while(true)
{
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any,0);
Byte[] receiveBytes = Client.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
Console.WriteLine(RemoteIpEndPoint.Address.ToString() + ":" + returnData.ToString() + " -" + counter);
counter++;
}
这是我的代码,用于从对等方向我的电脑发送消息(这里我感到困惑):
UdpClient client = new UdpClient(AddressFamily.InterNetworkV6);
byte[] Message = Encoding.ASCII.GetBytes("Hello my fiend");
//not sure what to put here .. but the following works and print results in the listener console from within my LAN
client.Send(Message, Message.Length, new IPEndPoint(IPAddress.Parse("2001:0:53aa:64c:3057:6dae:4308:b55e"), 23456));
System.Threading.Thread.Sleep(1000);