Get the Ip Address of the Remote Host

Get the IP address of the remote host

It's possible to do that, but not very discoverable - you need to use the property bag from the incoming request, and the property you need to access depends on whether you're using the Web API under IIS (webhosted) or self-hosted. The code below shows how this can be done.

private string GetClientIp(HttpRequestMessage request)
{
if (request.Properties.ContainsKey("MS_HttpContext"))
{
return ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
}

if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
{
RemoteEndpointMessageProperty prop;
prop = (RemoteEndpointMessageProperty)request.Properties[RemoteEndpointMessageProperty.Name];
return prop.Address;
}

return null;
}

How to get the IP address for remote host using Java

Use getHostAddress() as below:

    InetAddress inetAddress = InetAddress.getByName("www.google.com");
String ipAddress = inetAddress.getHostAddress();
System.out.println(ipAddress );//prints 66.152.109.61

Find IP address of remote server

You can check the endpoints with netstat: netstat -an -p tcp

It comes with Windows.

How to get local network IP address of a remote computer

After playing around with this problem, I realize that the adapters on remote string could not be public due to security issue. Thus, we don't have an exactly way to know which IP address is VPN.

Moreover, VPN address is created by VPN server. Therefore, that VPN address could be anything, even similar to our local IP. In other words, we cannot guess VPN address any way.

node.js http(s): get ip address of remote server

Try use res.connection.remoteAddress

like this:

var http = require('http');

http.get('http://www.google.com', function(res) {
console.log(res.connection.remoteAddress);
});


Related Topics



Leave a reply



Submit