Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I want to get the wan IP from the website.I tried but it doesn't show the IP.Also I don't want the html tags,only the IP address I want that i want
Here is my code.
XML
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Dim cTemp As String
Dim arTemp() As String

Call URLDownloadToFile(0, "http://www.whatismyip.com", App.Path & "\ipaddress.htm", 0, 0)
If Dir(App.Path & "\ipaddress.htm") <> "" Then
    cTemp = CreateObject("Scripting.FileSystemObject").OpenTextFile(App.Path & "\ipaddress.htm").ReadAll
    If InStr(cTemp, "<h1>") > 0 Then
        arTemp = Split(Replace(cTemp, "</h1>", "<h1>"), "<h1>")
        MsgBox arTemp(1)
    Else
        MsgBox "Unknown IP Address"
    End If
    Kill App.Path & "\ipaddress.htm"
Else
    MsgBox "Unknown IP Address"
End If


Also I need a code that will change the client ip to server ip when connected.

Please help me..

Thank you
Posted

1 solution

Get the client IP is easy: HttpContext.Current.Request.UserHostAddress will give it to you directly.

Getting the website IP address is only slightly more complex: http://www.howtogeek.com/howto/programming/get-ip-address-from-dns-hostname-in-c/[^] - it's in C#, but it's pretty obvious!

You cannot change the client IP address - it is not issued to you or by anything you have control over. If nothing else, if you could change it, you wouldn't be able to respond to the user...
 
Share this answer
 
Comments
Member 10245054 11-Jan-14 12:31pm    
I dont want the website ipaddress, what I want is the website www.whatsmyip.org shows the ipaddress I want that ip address through vb6 code saved in textbox or string
OriginalGriff 11-Jan-14 12:39pm    
Whatsmyip.com returns the ip address of the client that calls it: so if you access it from your PC via a browser, it gives you the public ip of your router: the address it presents to the internet.
If you access it via software running on your webserver, then it would return the ip address that the webserver presents to the internet via the connection it makes.

So which ip do you want?
Member 10245054 11-Jan-14 12:39pm    
More info, I had created 2 vb app client and server were in when client is connected to server its ip will changed to server ip like proxy server
Member 10245054 11-Jan-14 13:17pm    
I want the public ip..if you provide me the code will be appreciated
OriginalGriff 12-Jan-14 4:31am    
I repeat: "So which ip do you want?"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900