Thanks Zestq..its working fine.. This is what I exactly want..
I really wonder why others given examples with server variables.
I already said, I tried with server variables and couldnt succeed in INTRNET environment where proxy is hiding the original IP.
API's under DNS class are solution for my problem.
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.
NOTE: when you run this it will give you "127.0.0.1", 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
when any visitor or client hits ur page it will give you the exact IP Address of the Client.
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.
client ip addressvisitors ip addressclient machine ip address
Hi Hideyoshi here is the VB version of both of my codes:
Dim strHostName As String = System.Net.Dns.GetHostName()
Dim clientIPAddress As String = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString()
Dim clientIPAddress As String = Me.Page.Request.ServerVariables("REMOTE_ADDR"
Following site address is the converter of VB.NET code to C# and vice versa (I have also used this site 2 convert my code).
balamurugan ...
Member
31 Points
7 Posts
Re: Get users IP address
Jan 08, 2008 05:42 AM|LINK
Getting user's country name using ip Address
http://balanagaraj.wordpress.com/2008/01/07/get-users-country-name-using-ip-address/
Bala
http://balanagaraj.wordpress.com
vitta
Member
29 Points
14 Posts
Re: Get users IP address
Jan 24, 2008 05:16 PM|LINK
Even I have simillar kind of problem.
"REMOTE_ADDR")We have intranet application and I need to cature the IPAddress of the client.
I am trying to capture the remote address.
I tried in different ways as below.. but the result of all is 127.0.0.1
HttpContext.Current.Request.ServerVariables(
Request.ServerVariables("REMOTE_HOST")
Request.UserHostAddress()
Request.UserHostName()
I guess firewall/NAT Box hiding internal IP addresses.
is there any way to get actual IP.
Thanks in advance.
zestq
Member
94 Points
61 Posts
Re: Get users IP address
Feb 06, 2008 12:54 PM|LINK
Hi vitta, I got the same problem and I found the solution by doing dis:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
I got this solution from C# corner. website
client ip address
satender88
Member
16 Points
46 Posts
Re: Get users IP address
Feb 12, 2008 06:22 AM|LINK
This example demonstrates how to find out the visitor's browser type, IP address, and more:
<html> <body> <p> <b>You are browsing this site with:</b> <%Response.Write(Request.ServerVariables("http_user_agent"))%> </p> <p> <b>Your IP address is:</b> <%Response.Write(Request.ServerVariables("remote_addr"))%> </p> <p> <b>The DNS lookup of the IP address is:</b> <%Response.Write(Request.ServerVariables("remote_host"))%> </p> <p> <b>The method used to call the page:</b> <%Response.Write(Request.ServerVariables("request_method"))%> </p> <p> <b>The server's domain name:</b> <%Response.Write(Request.ServerVariables("server_name"))%> </p> <p> <b>The server's port:</b> <%Response.Write(Request.ServerVariables("server_port"))%> </p> <p> <b>The server's software:</b> <%Response.Write(Request.ServerVariables("server_software"))%> </p> </body> </html>ip
vitta
Member
29 Points
14 Posts
Re: Get users IP address
Mar 31, 2008 08:22 PM|LINK
Thanks Zestq..its working fine.. This is what I exactly want..
I really wonder why others given examples with server variables.
I already said, I tried with server variables and couldnt succeed in INTRNET environment where proxy is hiding the original IP.
API's under DNS class are solution for my problem.
Thanks again Zestq
Simon Deshai...
Member
144 Points
72 Posts
Re: Get users IP address
Apr 13, 2008 07:14 PM|LINK
Thanks this works for me.
HttpContext.Current.Request.UserHostAddress;
So I can log every user login and their IP.
I use it like this in c#. Using This Sql Connection class as MySql.
MySqlConnection MySql = new MySqlConnection();
string ip = HttpContext.Current.Request.UserHostAddress;
MySql.CreateConn();
MySql.Command = MySql.Connection.CreateCommand();
MySql.Command.CommandType = CommandType.Text;
MySql.Command.CommandText = "INSERT INTO dbo.[log.login] (userID, IP, DateTimeStamp, TargetPage) VALUES (" + myUserID + ", '" + ip + "', '" + DateTime.Now + "', '" + Server.UrlDecode(Request.QueryString["p"]) + "')";
MySql.Command.ExecuteNonQuery();
MySql.Command.Dispose();
MySql.CloseConn();
Rizwan328
Participant
1515 Points
358 Posts
Re: Get users IP address
May 04, 2008 01:13 PM|LINK
Thanks ZESTQ, It really works for me......
Cheers,
Muhammad Rizwan Javed
Sr. Software Engineer
Dubai, United Arab Emirates
Hideyoshi
Member
156 Points
97 Posts
Re: Get users IP address
May 08, 2008 02:44 AM|LINK
dear zestq,
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
I got this solution from C# corner. website
for the solution that you provided on February, Do u know how to solve it by using vb.NET?
Hope to hear anyone of you, thank you
zestq
Member
94 Points
61 Posts
Re: Get users IP address
Jun 12, 2008 11:14 AM|LINK
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.
To get the Client's IP Address, try this:
string
clientIPAddress = this.Page.Request.ServerVariables["REMOTE_ADDR"];NOTE: when you run this it will give you "127.0.0.1", 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 when any visitor or client hits ur page it will give you the exact IP Address of the Client.
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.
client ip address visitors ip address client machine ip address
zestq
Member
94 Points
61 Posts
Re: Get users IP address
Jun 12, 2008 11:21 AM|LINK
Hi Hideyoshi here is the VB version of both of my codes:
Dim strHostName As String = System.Net.Dns.GetHostName()
Dim clientIPAddress As String = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString()
Dim clientIPAddress As String = Me.Page.Request.ServerVariables("REMOTE_ADDR"
Following site address is the converter of VB.NET code to C# and vice versa (I have also used this site 2 convert my code).
http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
VB.NET code to C# Converter