Last post Jun 19, 2015 11:44 AM by Crater
Jun 18, 2015 05:57 PM|Crater|LINK
Dear List, I've been trying to get my laptop IP to log on my Azure website without any success.
Things work fine when running locally but after publishing, I think I can only get the Azure server IP.
I've tried everything I could find on the web.
//string looky1 = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
//string looky2 = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
//string strHostName = System.Net.Dns.GetHostName();
//string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
//string clientip = clientIPAddress.ToString();
//System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.whatismyip.org");
//request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE" + "6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
//System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
//using (System.IO.StreamReader reader = new StreamReader(response.GetResponseStream()))
// myExternalIP = reader.ReadToEnd();
//this.tbxLogonStatus.Text = "IP = " + myExternalIP.ToString();
private string GetIPInfo()
string ipString = "";
// Get a list of all network interfaces (usually one per network card, dialup, and VPN connection)
NetworkInterface networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface network in networkInterfaces)
// Read the IP configuration for each network
IPInterfaceProperties properties = network.GetIPProperties();
// Each network interface may have multiple IP addresses
foreach (IPAddressInformation address in properties.UnicastAddresses)
// We're only interested in IPv4 addresses for now
//if (address.Address.AddressFamily != AddressFamily.InterNetwork)
if (address.Address.AddressFamily.ToString().Length == 0 )
// Ignore loopback addresses (e.g., 127.0.0.1)
ipString += address.Address.ToString() + " (" + network.Name + ")";
They all worked locally but none of them successfully returned my laptop IP from Azure.
I want to log customer ip's to look for bad behavior on my web site.
Jun 19, 2015 03:51 AM|PatriceSc|LINK
And what happens when using #1? Note that you won't see necessarily your IP address but how it is exposed on the internet (ie the external web address for your proxy). Don't you have the same thing than when looking at
#2 and #3 is to read information about the local machine (so it just appears to work when the client and the server machine are the same,machine).
Also this kind of basic information should be already tracked in the IIS log depending on your exact final goal.
Jun 19, 2015 11:44 AM|Crater|LINK
This is very helpful information. I'll investigate the IIS angle first.