-
Jan 6th, 2011, 08:01 AM
#1
Thread Starter
Fanatic Member
VB.Net Simple function to get external IP-adress
This is The Code
Code:
Imports System.Net
Imports System.Text.RegularExpressions
Function GetExternalIP() As IPAddress
Dim lol As WebClient = New WebClient()
Dim str As String = lol.DownloadString("http://www.ip-adress.com/")
Dim pattern As String = "<h2>My IP address is: (.+)</h2>"
Dim matches1 As MatchCollection = Regex.Matches(str, pattern)
Dim ip As String = matches1(0).ToString
ip = ip.Remove(0, 21)
ip = ip.Replace("</h2>", "")
ip = ip.Replace(" ", "")
Return IPAddress.Parse(ip)
End Function
This is How to use it
Code:
Dim MyIP As IPAddress = GetExternalIP()
This code is an easy method to get your Ip-address. I've read that sites disclaimer and all the fine print and nothing said I'm not allowed to parse it's html code, although I'm not sure if their is a daily limit or not
This is my first code bank submission and I hope that it will help someone out
I did a search and didn't find something similar
Last edited by BlindSniper; Jan 6th, 2011 at 08:09 AM.
Reason: added Imports
-
Jan 11th, 2011, 03:57 AM
#2
Fanatic Member
Re: VB.Net Simple function to get external IP-adress
A similar way but utilizing Regular Expressions built in features:
vb Code:
Private Function GetMyIP() As IPAddress Dim outputIP As IPAddress Using wClient As New WebClient Dim myIP As String = Regex.Match(wClient.DownloadString("http://www.ip-adress.com/"), "(?<=<h2>My IP address is: )[0-9.]*?(?=</h2>)", RegexOptions.Compiled).Value outputIP = IPAddress.Parse(myIP) End Using Return outputIP End Function
Or if you want to get ugly
vb Code:
Private Function GetMyIP() As IPAddress Using wClient As New WebClient Return IPAddress.Parse(Regex.Match(wClient.DownloadString("http://www.ip-adress.com/"), "(?<=<h2>My IP address is: )[0-9.]*?(?=</h2>)", RegexOptions.Compiled).Value) End Using End Function
If I helped you out, please take the time to rate me
-
Jan 11th, 2011, 11:08 PM
#3
Fanatic Member
Re: VB.Net Simple function to get external IP-adress
Sorry for the double post but I felt I should share this, as it's a heck of a lot easier. Change your Imports to just System.Text and try the following.
vb Code:
Private Function GetMyIP() As Net.IPAddress Using wc As New Net.WebClient Return Net.IPAddress.Parse(Encoding.ASCII.GetString(wc.DownloadData("http://whatismyip.com/automation/n09230945.asp"))) End Using End Function
That returns your ip with no string formatting necessary.
If I helped you out, please take the time to rate me
-
Jul 26th, 2014, 03:06 PM
#4
Re: VB.Net Simple function to get external IP-adress
Since the last code doens't work anymore and people might still want to use it, I have an alternative but simular solution:
Code:
Private Function GetMyIP() As Net.IPAddress
Using wc As New Net.WebClient
Return Net.IPAddress.Parse(Encoding.ASCII.GetString(wc.DownloadData("http://tools.feron.it/php/ip.php")))
End Using
End Function
-
Jul 26th, 2014, 09:32 PM
#5
Hyperactive Member
Re: VB.Net Simple function to get external IP-adress
This is very simple, clever and cool, thanks for sharing!
-
Jul 29th, 2014, 02:39 PM
#6
Re: VB.Net Simple function to get external IP-adress
You're welcome, feron.it is my own domain and I'll keep this service running forever for free. It is just 2 line PHP
-
Jul 29th, 2014, 03:00 PM
#7
Hyperactive Member
Re: VB.Net Simple function to get external IP-adress
Could you write this in VBScript I'm not sure how to do this in VBScript. How to download and parse using VBScript
-
Jul 29th, 2014, 10:08 PM
#8
Re: VB.Net Simple function to get external IP-adress
Originally Posted by a_ahmed
Could you write this in VBScript I'm not sure how to do this in VBScript. How to download and parse using VBScript
You have posted in the wrong section for the language you want to use! VBscript is a different language to VB.NET. Please ask the question in a new thread in the ASP/VB Script section of the forum.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jul 29th, 2014, 10:25 PM
#9
Hyperactive Member
Re: VB.Net Simple function to get external IP-adress
Of course I know, but was hoping he would share a VBScript version of his shared code too
-
Jul 29th, 2014, 10:48 PM
#10
Re: VB.Net Simple function to get external IP-adress
Originally Posted by a_ahmed
Of course I know, but was hoping he would share a VBScript version of his shared code too
BlindSniper might not know VBScript though.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Sep 22nd, 2014, 12:16 PM
#11
Hyperactive Member
Re: VB.Net Simple function to get external IP-adress
I know I asked this before and I found a solution for vbscript:
vb Code:
Function MyIP_WinHTTP( ) Dim lngStatus, objHTTP, objMatch, objRE, strText, strURL MyIP_WinHTTP = "0.0.0.0" strURL = "http://tools.feron.it/php/ip.php" Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" ) objHTTP.Open "GET", strURL objHTTP.Send If objHTTP.Status = 200 Then MyIP_WinHTTP = objHTTP.ResponseText Set objHTTP = Nothing End Function
then just call myIP_WinHTTP() and put in a variable or echo it
-
Nov 21st, 2016, 09:21 AM
#12
New Member
Re: VB.Net Simple function to get external IP-adress
This can help
Code:
Public Structure DatosIPExterna
Dim IP As String
Dim CountryCode As String
Dim CountryName As String
Dim RegionCode As String
Dim RegionName As String
Dim City As String
Dim TimeZone As String
Dim Latitude As Double
Dim Longitude As Double
End Structure
Public Function GeoIP(Optional IP As String = Nothing) As DatosIPExterna
Dim DatosIP As New DatosIPExterna
Using client = New WebClient()
Try
Dim strFile As String
If IsNothing(IP) Then
strFile = client.DownloadString("http://freegeoip.net/xml")
Else
strFile = client.DownloadString(String.Format("http://freegeoip.net/xml/{0}", IP))
End If
Dim response As XElement = XElement.Parse(strFile)
With DatosIP
.IP = response.Element("IP").Value
.CountryCode = response.Element("CountryCode").Value
.CountryName = response.Element("CountryName").Value
.RegionCode = response.Element("RegionCode").Value
.RegionName = response.Element("RegionName").Value
.City = response.Element("City").Value
.TimeZone = response.Element("TimeZone").Value
.Latitude = CType(response.Element("Latitude").Value, Long)
.Longitude = CType(response.Element("Longitude").Value, Long)
End With
Catch ex As Exception
Return Nothing
End Try
End Using
Return DatosIP
End Function
-
Aug 21st, 2020, 08:44 AM
#13
New Member
Re: VB.Net Simple function to get external IP-adress
You're welcome, feron.it is my own domain and I'll keep this service running forever for free. It is just 2 line PHP
@Lightning Cool page! I wouldn't mind hosting this as well, you mind sharing the ip.php code?
Last edited by danielmaat; Aug 21st, 2020 at 08:47 AM.
-
Jan 2nd, 2022, 01:17 AM
#14
New Member
Re: VB.Net Simple function to get external IP-adress
first time caller, long time listener...
Originally Posted by danielmaat
@Lightning Cool page! I wouldn't mind hosting this as well, you mind sharing the ip.php code?
simple... in Perl:
In php:
Tags for this Thread
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
|