hi
i want to get current internet ip address in vb.net.
not localhost ip address. like as (http://www.ipchicken.com/ website return ip address)
please help me .
by
somu
hi
i want to get current internet ip address in vb.net.
not localhost ip address. like as (http://www.ipchicken.com/ website return ip address)
please help me .
by
somu
You can know real ip address only if your host (pc) have static internet ip address, not like 194.x.x.x or 10.x.x.x and other http://en.wikipedia.org/wiki/Private_network Otherwise try to send http request to service like www.ipchicken.com or other http://www.google.ru/search?hl=en&q=my+ip+address to know your ip address
This should do the trick:
http://www.vbdotnetheaven.com/UploadFile/prvn_131971/ipvb11162005073000AM/ipvb.aspx
I understand what you are wanting is the IP address as you appear on the internet and NOT your internal network IP. I've got some code somewhere I'll dig out for you but it basically comprised of this (from memory):
Like I say I'll try and dig out the code but this should be more than enough information for you to work on :-)
Something like this should get your current public IP.
Public Class Form1
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
End Sub
Public WithEvents wb As New WebBrowser
'before using wb add
'AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
Private Sub GetPubIP()
Try
'the site returns a string like "Current IP Address: 69.59.196.211"
wb.Navigate(New Uri("http://checkip.dyndns.org"))
Catch ex As Exception
'add error checking
End Try
End Sub
Private Sub wb_DocumentCompleted(ByVal sender As Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
'parse the reply
Dim parts() As String = wb.Document.Body.InnerText.Split(":"c)
Debug.WriteLine(parts(1).Trim)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
GetPubIP()
End Sub
End Class
Here's what you're looking for. I wrote a simple PHP script to return the IP address when called, then wrote this VB.Net code to call it at any time:
Public Function jnWhatIsMyExternalIP() As String
Dim strURL As String = "http://www.mycompanywebsite/jnNetworkTools/jnCheckIP.php"
Dim Request As System.Net.WebRequest = System.Net.WebRequest.Create(strURL)
Dim Response As System.Net.WebResponse = Request.GetResponse()
Dim Reader As New System.IO.StreamReader(Response.GetResponseStream())
Dim strMyIP As String = Reader.ReadToEnd()
Return strMyIP
End Function
Here's the PHP code that is in jnCheckIP.php:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
Calling the VB.Net function causes the users machine to call the PHP script on your server which then returns the users IP address.