Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, October 16, 2016 8:17 AM
Hello! I'm tring to do a HttpWebRequest to 123.456.789.01 address using POST method. And I have successfully get response. But, how to get the ip address of the server who send the response? I have try to use response.ResponseUri but it just showing same address 123.456.789.01. Any solution please?
All replies (9)
Sunday, October 16, 2016 8:50 AM
Look at the firewall logs....
Sunday, October 16, 2016 4:36 PM
Is there a way to do it in c#?
Sunday, October 16, 2016 5:25 PM
123.456.789.01 looks to be an WAN IP to a network on the Internet, and the machine that is probably on the protected LAN. I doubt that you are going to get the LAN IP of the machine.
Tuesday, October 18, 2016 1:30 PM
Hi Skypea,
Thank you for posting here.
For your question, may be HttpRequest.UserHostAddress Property could help you to get gets the IP host address of the remote client.
You could use IPEndPoint and Socket.RemoteEndPoint Property.
If you are using a connection-oriented protocol, the RemoteEndPoint property gets the EndPoint that contains the remote IP address and port number to which the Socket is connected. If you are using a connectionless protocol, RemoteEndPoint contains the default remote IP address and port number with which the Socket will communicate. You must cast this EndPoint to an IPEndPoint before retrieving any information. You can then call the IPEndPoint.Address method to retrieve the remote IPAddress, and the IPEndPoint.Port method to retrieve the remote port number.
I hope this would be helpful to you.
Best Regards,
Wendy
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Tuesday, October 18, 2016 4:01 PM
For your question, may be HttpRequest.UserHostAddress Property** could help you to get gets the IP host address of the remote client.**
You could use IPEndPoint** and** Socket.RemoteEndPoint Property.
How can that be and what good is it when the IP for the remote host is known of 123.456.789.01, because otherwise, the OP wouldn't be able to make contact with the remote site?
And any firewall or router solution that is protecting the protected LAN would be worthless , if somehow, the client application was able to spoof the IP of the machine hosting the server on the LAN.
Thursday, October 20, 2016 8:55 AM
Hi DA924x,
Thanks for your suggestion.
I try to test my reply again and find some wrong. It could get the local ip address.
But I found another way to get the ip address from response vis hostname.
Thanks again.
Best Regards,
Wendy
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Thursday, October 20, 2016 8:58 AM
Hi Skypea,
Please try the following code. I try to get the ip address from the response hostname.
Here is the code.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace URL_IP_Address
{
class Program
{
static void Main(string[] args)
{
// Create a request for the URL.
WebRequest request = WebRequest.Create("https://www.google.com/");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string hostname = response.ResponseUri.Host;
IPHostEntry host;
host = Dns.GetHostEntry(hostname);
Console.WriteLine("GetHostEntry({0}) returns:", hostname);
foreach (IPAddress ip in host.AddressList)
{
Console.WriteLine(" {0}", ip);
}
Console.ReadKey();
}
}
}
Here is the output.

Best Regards,
Wendy
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Thursday, October 20, 2016 12:01 PM
216.58.197.163 is a Wan/Internet IP to Google site. The OP knows the Wan/Internet IP to the remote site of 123.465.789.1.
What the OP is never going to get is the LAN IP of the machine that is setting on the protected LAN that is hosting the Web server.
Thursday, October 20, 2016 12:43 PM
Try this.
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach(IPAddress address in localIPs)
MessageBox.Show(address.ToString());