如何获取响应 WebResponse C# 的服务器的 IP 地址

发布于 2024-08-15 07:48:22 字数 216 浏览 3 评论 0原文

我试图在 C# 中找到响应我的 WebRequest 的 IP 地址(不是主机名)。我不想进行 DNS 解析,因为在这种情况下,返回的 DNS 记录不是响应请求的服务器。例如:

客户 ->负载均衡器-> Web 服务器

DNS 服务器将使用负载均衡器的 IP 进行响应。假设响应的 Web 服务器不通过负载均衡器返回,则 IP 地址将是我正在尝试查找的实际 Web 服务器。

I am trying to find the ip address (not the hostname) that responded to my WebRequest in C#. I do not want to do a DNS resolution, because their are cases where the DNS records returned are not the servers responding to the request. For ex:

Client -> Load Balancer -> Web Server

The DNS server would respond with the Load Balancer's IP. Assuming the responding Web server is not going back through the Load Balancer, the IP address would then be the actual Web server which is what I am trying to find.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你好,陌生人 2024-08-22 07:48:22

您有权访问服务器端代码吗?或者到网络服务器配置?您始终可以将机器 IP 或任何您想要的标识符放在自定义标头中,然后在客户端上查找。

至于您原来的问题,我不认为 HttpWebRequest/HttpWebResponse 类会在任何地方公开信息。

Do you have access to the server side code? Or to the web server configuration? You could always place the machines IP, or whatever identifier you'd like, in a custom header and look for that on the client.

As for your original question, I do not believe that information is exposed anywhere by the HttpWebRequest/HttpWebResponse classes.

初吻给了烟 2024-08-22 07:48:22

我认为您必须深入了解 OSI,并创建并利用您自己的套接字;
那么您将可以访问 RemoteEndPoint 属性(至少在您的套接字已连接或已连接到之后),如下所示:

Socket sprocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);< br>
sprocket.Connect("www.google.com", 80);
字符串 IPAddressOfRespondingServer = ((IPEndPoint)sprocket.RemoteEndPoint).Address.ToString();

I think you'll have to go OSI-dipping, and create and harness your own socket;
then you'll have access to the RemoteEndPoint property (at least after your socket has connected, or been connected to) like so :

Socket sprocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sprocket.Connect("www.google.com", 80);
string IPAddressOfRespondingServer = ((IPEndPoint)sprocket.RemoteEndPoint).Address.ToString();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文