Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, May 25, 2012 4:55 PM
How can I use my VB.NET application to get the public IP address of my computer?
All replies (5)
Friday, May 25, 2012 5:30 PM ✅Answered | 4 votes
Hi Logan,
here is the code:
Imports System.NetImports System.IO'http://www.dotnetobject.com/showthread.php?tid=27''' <summary>''' Router IP ermitteln. Ellen Ramcke 2011''' </summary>''' <remarks></remarks>Public Class Form1 Private Sub btnGetIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetIP.Click Dim client As New WebClient '// Add a user agent header in case the requested URI contains a query. client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)") Dim baseurl As String = "http://checkip.dyndns.org/" ' with proxy server only: Dim proxy As IWebProxy = WebRequest.GetSystemWebProxy() proxy.Credentials = CredentialCache.DefaultNetworkCredentials client.Proxy = proxy Dim data As Stream Try data = client.OpenRead(baseurl) Catch ex As Exception MsgBox("open url " & ex.Message) Exit Sub End Try Dim reader As StreamReader = New StreamReader(data) Dim s As String = reader.ReadToEnd() data.Close() reader.Close() s = s.Replace("<html><head><title>Current IP Check</title></head><body>", "").Replace("</body></html>", "").ToString() 'MessageBox.Show(s) Me.Text = s End SubEnd Class
Make a new Form project, copy the code into the code window and place a button named btnGetIP on Form.
regards Ellen
Ich benutze/ I'm using VB2008 & VB2010
Friday, May 25, 2012 5:51 PM ✅Answered | 1 vote
heres another way to do it:
Function GetIpAddress() As String
Dim ip As New WebClient
Return ip.DownloadString("http://automation.whatismyip.com/n09230945.asp")
End Function
If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.
Wednesday, July 31, 2013 10:49 PM
It's Perfect..... my lan have a proxy.....but my credential chache is reuses whit this algorithm.....sorry for my english,.......good work from Perú
Wednesday, February 27, 2019 4:26 AM
"http://automation.whatismyip.com/n09230945.asp" does't work any more. Any other link available?
Sorry for the silly question. Used "http://checkip.dyndns.org/" used from Ellen post. It works fine. Thanks to all of you
Wednesday, February 27, 2019 7:19 AM
It's Perfect..... my lan have a proxy.....but my credential chache is reuses whit this algorithm.....sorry for my english,.......good work from Perú
If that one ever stops you can create your own ip provider with a PHP page:
<?
$ip = $_SERVER['REMOTE_ADDR'];
die($ip);
?>
Don't forget to vote for Helpful Posts and Mark Answers!
*This post does not reflect the opinion of Microsoft, or its employees.