How do I get the IP address of the server that calls my ASP.NET page? I have seen stuff about a Response object, but am very new at c#. Thanks a ton.
The above is slow as it requires a DNS call (and will obviously not work if one is not available). You can use the code below to get a map of the current pc's local IPV4 addresses with their corresponding subnet mask:
public static Dictionary GetAllNetworkInterfaceIpv4Addresses()
{
var map = new Dictionary();
foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (var uipi in ni.GetIPProperties().UnicastAddresses)
{
if (uipi.Address.AddressFamily != AddressFamily.InterNetwork) continue;
if (uipi.IPv4Mask == null) continue; //ignore 127.0.0.1
map[uipi.Address] = uipi.IPv4Mask;
}
}
return map;
}
warning: this is not implemented in Mono yet