获取远程套接字端点的 IP 地址
如何确定已连接套接字的远程 IP 地址?
我有一个可以访问的 RemoteEndPoint 对象及其 AddressFamily 成员。
我如何利用这些来查找 IP 地址?
谢谢!
目前正在尝试
IPAddress.Parse( testSocket.Address.Address.ToString() ).ToString();
为本地主机端点获取 1.0.0.127 而不是 127.0.0.1。这是正常的吗?
How do I determine the remote IP Address of a connected socket?
I have a RemoteEndPoint object I can access and well as its AddressFamily member.
How do I utilize these to find the ip address?
Thanks!
Currently trying
IPAddress.Parse( testSocket.Address.Address.ToString() ).ToString();
and getting 1.0.0.127 instead of 127.0.0.1 for localhost end points. Is this normal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://msdn.microsoft.com/en -us/library/system.net.sockets.socket.remoteendpoint.aspx
然后,您可以调用 IPEndPoint..::.Address 方法来检索远程 IPAddress,并调用 IPEndPoint..::.Port 方法来检索远程 IPAddress。检索远程端口号。
更多来自链接(修复了很多呵呵):
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.remoteendpoint.aspx
You can then call the IPEndPoint..::.Address method to retrieve the remote IPAddress, and the IPEndPoint..::.Port method to retrieve the remote port number.
More from the link (fixed up alot heh):
RemoteEndPoint 是一个属性,其类型为 System.Net.EndPoint 继承自 System.Net.IPEndPoint。
如果您查看 IPEndPoint 的成员,您'您会看到有一个
Address
属性。RemoteEndPoint is a property, its type is System.Net.EndPoint which inherits from System.Net.IPEndPoint.
If you take a look at IPEndPoint's members, you'll see that there's an
Address
property.我在 VB.NET 中编写了这段代码,但你可以翻译。
假设您有变量 Client 作为 TcpClient
希望它有帮助!干杯。
I've made this code in VB.NET but you can translate.
Well pretend you have the variable Client as a TcpClient
Hope it helps! Cheers.