|
-
Mar 11th, 2013, 08:42 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Get client ip
in asp.net ( excuse please it's a duplicate thread)
how to get the client ip
vb.net Code:
Dim Ip_TcpIp As String
Ip_TcpIp = Request.UserHostAddress()
but it is resulting me
::1
-
Mar 11th, 2013, 09:43 PM
#2
Thread Starter
PowerPoster
Re: Get client ip
Any body , i tried a lot versions but suspect that the code is returning the ipv6 of my own system
ofcourse the request is also from my laptop.
but how i could get the ipv4
-
Mar 11th, 2013, 09:44 PM
#3
Thread Starter
PowerPoster
Re: Get client ip
Any body , i tried a lot versions but suspect that the code is returning the ipv6 of my own system
ofcourse the request is also from my laptop.
but how i could get the ipv4
-
Mar 11th, 2013, 10:35 PM
#4
Re: Get client ip
Who's IP address are you trying to get ?
-
Mar 12th, 2013, 06:56 AM
#5
Re: Get client ip
Try this. It will get all of the IP addresses associated with your local interface.
Code:
Dim strHostName As String
Dim strIPAddress As String
strHostName = System.Net.Dns.GetHostName()
Dim iphe As Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)
For Each ip As Net.IPAddress In iphe.AddressList
Debug.WriteLine(ip.ToString)
Select Case True
Case ip.AddressFamily = Net.Sockets.AddressFamily.InterNetwork
Stop 'IPv4
Case ip.AddressFamily = Net.Sockets.AddressFamily.InterNetworkV6
Stop 'IPv6
End Select
Next
-
Mar 12th, 2013, 07:44 AM
#6
Re: Get client ip
But what if he wants to get his public IP address ?
-
Mar 12th, 2013, 07:50 AM
#7
Re: Get client ip
If the OP wants the public IP they will have to get a response from a site that provides the public IP, like http://checkip.dyndns.org/ and parse it. Depending on the ISP there is no guarantee that it is constant.
It would look something like this
Code:
Dim myWebRequest As Net.WebRequest = Net.WebRequest.Create("http://checkip.dyndns.org/")
Dim myWebResponse As Net.WebResponse = myWebRequest.GetResponse()
Dim ReceiveStream As IO.Stream = myWebResponse.GetResponseStream()
Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New IO.StreamReader(ReceiveStream, encode)
Dim s As String = readStream.ReadToEnd
Debug.WriteLine(s)
myWebResponse.Close()
Last edited by dbasnett; Mar 12th, 2013 at 08:28 AM.
-
Mar 12th, 2013, 09:16 PM
#8
Thread Starter
PowerPoster
Re: Get client ip
Sorry for the delay in reply
i need the client's IP from whom i received request
i will try the code
thanks one & all
-
Mar 12th, 2013, 09:19 PM
#9
Re: Get client ip
Tell me, what does UserHostName return ?
-
Mar 13th, 2013, 02:56 AM
#10
Thread Starter
PowerPoster
Re: Get client ip
thanks niya
::1
where as my system ip is 192.168.1.21
what i decided is
let me first connect from other system to my laptop ( i,e ) development machine
and
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|