Get users IP addresshttp://forums.asp.net/t/892765.aspx/1?Get+users+IP+addressThu, 03 Mar 2011 03:57:30 -0500892765953638http://forums.asp.net/p/892765/953638.aspx/1?Get+users+IP+addressGet users IP address I need to modify the Send Thoughts module so that I will get the users public IP address.<br> <br> Can someone please provide some light on how I might accomplish this?<br> <br> 2005-06-11T15:06:36-04:00958957http://forums.asp.net/p/892765/958957.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>You may be able accomplish what you want using the Request.Servervariables(&quot;REMOTE_ADDR&quot;) header.</p> <p>These may help:<br> <a href="http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=577">http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=577</a><br> <a href="http://www.w3schools.com/asp/coll_servervariables.asp">http://www.w3schools.com/asp/coll_servervariables.asp</a></p> 2005-06-16T12:15:14-04:001375457http://forums.asp.net/p/892765/1375457.aspx/1?Re+Get+users+IP+addressRe: Get users IP address This link will be useful<br> http://www.vikramlakhotia.com/Post.aspx?postID=12 2006-08-19T17:27:01-04:001446119http://forums.asp.net/p/892765/1446119.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p><span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.UserHostAddress;</span><span class="v11"> </span><br> or <br> <span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.ServerVariables[&quot;REMOTE_ADDR&quot;];</span></p> <p><span style="font-size:10pt; color:green; font-family:'Courier New'"><font color="#000000">To get the IP address of the machine and not the proxy use the following code<span class="v11"></span></font></p> <p class="MsoNormal"><span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.ServerVariables[&quot;HTTP_X_FORWARDED_FOR&quot;];</span></p> </span> <p></p> 2006-10-30T07:41:22-05:001796357http://forums.asp.net/p/892765/1796357.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p></p> <blockquote><span class="icon-blockquote"></span> <h4>etariq</h4> <span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.ServerVariables[&quot;HTTP_X_FORWARDED_FOR&quot;];</span></blockquote> <p></p> <p>I tried that and it didn't work. No IP address is showing.</p> 2007-07-10T17:00:50-04:001802404http://forums.asp.net/p/892765/1802404.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Take a look at the log module as it shows IP information.&nbsp; You can just copy that functionality.&nbsp;</p> 2007-07-13T13:33:56-04:001802450http://forums.asp.net/p/892765/1802450.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Not sure what you mean by log module. Where do I look for and what do I need to copy?</p> 2007-07-13T13:54:58-04:001802490http://forums.asp.net/p/892765/1802490.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Rainbow has a log module.&nbsp; You can find this on the portal by going on the Admin menu and clicking on logs and then&nbsp; Monitoring and Logs.&nbsp;&nbsp; This will show you IP info and you can get the functionality from DesktopModules\Monitoring.<br> </p> 2007-07-13T14:18:08-04:001802505http://forums.asp.net/p/892765/1802505.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>I'm still not clear what you mean. I don't have admin rights to the web server. I only have rights to my own little web space. So I'm not sure what you mean by admin menu or DesktopModules\Monitorings. </p> 2007-07-13T14:25:20-04:001802520http://forums.asp.net/p/892765/1802520.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>When you login to rainbow, you see the admin menu correct? &nbsp; Off of the admin menu is a logs tab, off the logs tab is monitoring.&nbsp; I dont mean admin to the server; I mean admin to your portal.&nbsp;</p> 2007-07-13T14:29:38-04:002095920http://forums.asp.net/p/892765/2095920.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Getting user's country name using ip Address</p> <p><a href="http://balanagaraj.wordpress.com/2008/01/07/get-users-country-name-using-ip-address/">http://balanagaraj.wordpress.com/2008/01/07/get-users-country-name-using-ip-address/</a>&nbsp;</p> <p>&nbsp;</p> 2008-01-08T05:42:06-05:002130865http://forums.asp.net/p/892765/2130865.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <font size="2"> <p>Even I have&nbsp;simillar kind of problem.<br> We have intranet&nbsp;application and&nbsp;I need to cature the &nbsp;IPAddress of the client.<br> <br> I am trying to capture the remote address.<br> I tried&nbsp; in different ways as below.. but the result of all is <strong>127.0.0.1<br> </strong><br> HttpContext.Current.Request.ServerVariables(</font><font color="#a31515" size="2">&quot;REMOTE_ADDR&quot;</font><font size="2">)<br> <font size="2">Request.ServerVariables(</font><font color="#a31515" size="2">&quot;REMOTE_HOST&quot;</font><font size="2">)<br> </font><font size="2">Request.UserHostAddress()<br> <font size="2">Request.UserHostName()</font></font></font></p> <p><font size="2"><font size="2"><font size="2"><strong>I guess firewall/NAT Box&nbsp;hiding internal IP addresses.<br> is there any way to&nbsp;get actual IP.<br> <br> Thanks in advance.</strong></font></font></font></p> <font size="2"><font size="2"><font size="2"></font></font></font><font size="2"><font size="2"><font size="2"> <p><br> </p> <p></font><br> &nbsp;</p> </font></font><font size="2"><font size="2"> <p></font><font size="2">&nbsp;</p> </font></font> 2008-01-24T17:16:09-05:002156655http://forums.asp.net/p/892765/2156655.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Hi vitta, I got the same problem and I found the solution by doing dis:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strHostName = System.Net.Dns.GetHostName();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();</p> <p>I got this solution from C# corner. website</p> 2008-02-06T12:54:21-05:002167498http://forums.asp.net/p/892765/2167498.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>This example demonstrates how to find out the visitor's browser type, IP address, and more:</p> <pre>&lt;html&gt; &lt;body&gt; &lt;p&gt; &lt;b&gt;You are browsing this site with:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;http_user_agent&quot;))%&gt; &lt;/p&gt; &lt;p&gt; &lt;b&gt;Your IP address is:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;remote_addr&quot;))%&gt; &lt;/p&gt; &lt;p&gt; &lt;b&gt;The DNS lookup of the IP address is:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;remote_host&quot;))%&gt; &lt;/p&gt; &lt;p&gt; &lt;b&gt;The method used to call the page:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;request_method&quot;))%&gt; &lt;/p&gt; &lt;p&gt; &lt;b&gt;The server's domain name:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;server_name&quot;))%&gt; &lt;/p&gt; &lt;p&gt; &lt;b&gt;The server's port:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;server_port&quot;))%&gt; &lt;/p&gt; &lt;p&gt; &lt;b&gt;The server's software:&lt;/b&gt; &lt;%Response.Write(Request.ServerVariables(&quot;server_software&quot;))%&gt; &lt;/p&gt; &lt;/body&gt; &lt;/html&gt;</pre> 2008-02-12T06:22:48-05:002267221http://forums.asp.net/p/892765/2267221.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Thanks Zestq..its working fine.. This is what I exactly want.. <br> I really wonder why others&nbsp;given examples with server variables.<br> I already said, I tried with server variables and couldnt succeed in INTRNET environment where proxy is hiding the original IP.</p> <p>API's under DNS class are solution for my problem.</p> <p>Thanks again Zestq</p> <p><br> &nbsp;</p> <p><br> &nbsp;</p> <p><br> &nbsp;</p> <p><br> &nbsp;</p> 2008-03-31T20:22:17-04:002294998http://forums.asp.net/p/892765/2294998.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p></p> <blockquote><span class="icon-blockquote"></span> <h4>etariq</h4> <p><span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.UserHostAddress;</span><span class="v11"> </span><br> or <br> <span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.ServerVariables[&quot;REMOTE_ADDR&quot;];</span></p> <span style="font-size:10pt; color:green; font-family:'Courier New'"><font color="#000000">To get the IP address of the machine and not the proxy use the following code<span class="v11"></span></font> </span><span style="font-size:10pt; color:green; font-family:'Courier New'"> <p class="MsoNormal"><span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.ServerVariables[&quot;HTTP_X_FORWARDED_FOR&quot;];</span></p> </span> <p>&nbsp;</p> <p></p> </blockquote> <p></p> <p>&nbsp;</p> <p>Thanks this works for me.</p> <p><span style="font-size:10pt; color:green; font-family:'Courier New'">HttpContext.Current.Request.UserHostAddress;</span><span class="v11"> </span></p> <p><span class="v11">So I can log every user login and their IP.</span></p> <p><span class="v11">I use it like this in c#. Using <a class="" title="How To: Connect to SQL using C# and SELECT, INSERT or any other SQL STATEMENT?" href="http://weblog.simondeshaies.com/post/2008/03/How-To-Connect-to-SQL-using-C-and-SELECT2c-INSERT-or-any-other-SQL-STATEMENT.aspx" target="_blank"> This</a> Sql Connection class as MySql.<br> <br> <br> </span><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#2b91af" size="2"><font color="#2b91af" size="2">MySqlConnection</font></font><font color="#000000" size="2"> MySql = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font color="#000000" size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">MySqlConnection</font></font><font size="2"><font color="#000000">();<br> </font></font><br> string</font></font><font size="2"> ip = </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">HttpContext</font></font><font size="2">.Current.Request.UserHostAddress;<br> </font><font size="2"><font size="2"><br> MySql.CreateConn();<br> <br> MySql.Command = MySql.Connection.CreateCommand();<br> </font>MySql.Command.CommandType = </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">CommandType</font></font><font size="2">.Text;<br> MySql.Command.CommandText = </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;INSERT INTO dbo.[log.login] (userID, IP, DateTimeStamp, TargetPage) VALUES (&quot;</font></font><font size="2"> &#43; myUserID &#43; </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;, '&quot;</font></font><font size="2"> &#43; ip &#43; </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;', '&quot;</font></font><font size="2"> &#43; </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">DateTime</font></font><font size="2">.Now &#43; </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;', '&quot;</font></font><font size="2"> &#43; Server.UrlDecode(Request.QueryString[</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;p&quot;</font></font><font size="2">]) &#43; </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;')&quot;</font></font><font size="2">;<br> MySql.Command.ExecuteNonQuery();<br> MySql.Command.Dispose();<br> <font size="2"><br> MySql.CloseConn();</font></font></p> 2008-04-13T19:14:53-04:002336397http://forums.asp.net/p/892765/2336397.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Thanks ZESTQ, It really works for me......<br> </p> <br> 2008-05-04T13:13:13-04:002344439http://forums.asp.net/p/892765/2344439.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>dear zestq,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strHostName = System.Net.Dns.GetHostName();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();</p> <p>I got this solution from C# corner. website</p> <p>&nbsp;</p> <p>for the solution that you provided on February, Do u know how to solve it by using vb.NET?</p> <p>Hope to hear anyone of you, thank you</p> 2008-05-08T02:44:21-04:002418698http://forums.asp.net/p/892765/2418698.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Hi guyz, The solution I have provided gives the IP Address but If you look into it, It gives you the server IP not the client;s IP Address, while I guess we all need the client's IP Address or the visitor's IP. </p> <p>To get the Client's IP Address, try this: </p> <font color="#0000ff" size="2"> <p>string</font><font size="2"> clientIPAddress = </font><font color="#0000ff" size="2">this</font><font size="2">.Page.Request.ServerVariables[</font><font color="#800000" size="2">&quot;REMOTE_ADDR&quot;</font><font size="2">];</font></p> <p><font size="2">NOTE: when you run this it will give you &quot;127.0.0.1&quot;, this is because, you are using from the HOST Machine i.e. the application is on ur machine and it is giving you, ur IP address but <strong>when any visitor or client hits ur page it will give you the exact IP Address of the Client</strong>. </font></p> <p><font size="2"><font color="#800000"><em><u>I have checked this on my LAN and its working fine,,,,,try this and if it fails do inform me or any 1 got any better solution please let me know.</u></em></font></font></p> 2008-06-12T11:14:17-04:002418715http://forums.asp.net/p/892765/2418715.aspx/1?Re+Get+users+IP+addressRe: Get users IP address <p>Hi <strong>Hideyoshi </strong>here is the VB version of both of my codes:</p> <p>Dim strHostName As String = System.Net.Dns.GetHostName()<br> Dim clientIPAddress As String = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString()<br> Dim clientIPAddress As String = Me.Page.Request.ServerVariables(&quot;REMOTE_ADDR&quot;</p> <p>Following&nbsp;site&nbsp;address is&nbsp;the converter of VB.NET&nbsp;code to C# and vice versa (I have also used this site 2 convert my code).</p> <p>&nbsp;<a href="http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx</a></p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-06-12T11:21:05-04:00