VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Obtain Public IP - THE REAL WAY! Get HTML from any web like showmyip and get Public IP in a String.

by Cristian Deluxe (1 Submission)
Category: Internet/HTML
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Mon 15th October 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Obtain Public IP - THE REAL WAY! Get HTML from any web like showmyip and get Public IP in a String. Only one function! Copy, paste and GO!! It

Rate Obtain Public IP - THE REAL WAY! Get HTML from any web like showmyip and get Public IP in a String.



' Please send your GetPublicIp modded version to me!!
' V0.1 - Original Languaje: Spanish (Sorry for my bad translation)

' Usage: Dim PublicIP as String = GetPublicIP()

Public Function GetPublicIP() As String
Try
Dim URLIP As String = "http://www.showmyip.com"
Dim RawHTML As String = ""

If My.Computer.Network.IsAvailable Then
Dim WebClient As New System.Net.WebClient
Dim srHTML As New System.IO.StreamReader(WebClient.OpenRead(URLIP))
RawHTML = srHTML.ReadToEnd()
srHTML.Close()
srHTML.Dispose()
srHTML = Nothing
WebClient.Dispose()
WebClient = Nothing
Else
Return "Network Card Disconnected"
End If

If RawHTML <> "" Then
Dim reg As RegularExpressions.Regex
Dim mc As RegularExpressions.MatchCollection
reg = New RegularExpressions.Regex("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b", RegularExpressions.RegexOptions.IgnoreCase Or RegularExpressions.RegexOptions.Compiled Or RegularExpressions.RegexOptions.Multiline)
mc = reg.Matches(RawHTML)
If mc.Count > 0 Then
Return Trim(mc.Item(0).ToString)
Else
Return "HTML no contains any IP"
End If
reg = Nothing
mc = Nothing
Else
Return "HTML can't be downloaded"
End If
Catch ex As Exception
MessageBox.Show("Error" & vbNewLine & ex.Message & vbNewLine & ex.ToString)
Return "Error"
End Try
End Function

Download this snippet    Add to My Saved Code

Obtain Public IP - THE REAL WAY! Get HTML from any web like showmyip and get Public IP in a String. Comments

No comments have been posted about Obtain Public IP - THE REAL WAY! Get HTML from any web like showmyip and get Public IP in a String.. Why not be the first to post a comment about Obtain Public IP - THE REAL WAY! Get HTML from any web like showmyip and get Public IP in a String..

Post your comment

Subject:
Message:
0/1000 characters