Sinisterly
[VB.NET] Getting your own IP - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.NET] Getting your own IP (/Thread-VB-NET-Getting-your-own-IP)



[VB.NET] Getting your own IP - Distance - 10-26-2015

getting your own ip in vb.net 

Code:
Private Function GetMyIP()         Dim ExternalIP As String = "Null"           Try             ExternalIP = (New WebClient()).DownloadString("http://checkip.dyndns.org/")             ExternalIP = (New Regex("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) _                          .Matches(ExternalIP)(0).ToString()         Catch exc As Exception             ExternalIP = "Null"         End Try           Return ExternalIP End Function



RE: [VB.NET] Getting your own IP - Killpot - 10-27-2015

Why not just use http://ipinfo.io/ip


RE: [VB.NET] Getting your own IP - ɘxɘ - 10-27-2015

(10-26-2015, 08:37 AM)Distance Wrote: getting your own ip in vb.net 

Code:
Private Function GetMyIP()         Dim ExternalIP As String = "Null"           Try             ExternalIP = (New WebClient()).DownloadString("http://checkip.dyndns.org/")             ExternalIP = (New Regex("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) _                          .Matches(ExternalIP)(0).ToString()         Catch exc As Exception             ExternalIP = "Null"         End Try           Return ExternalIP End Function

Way more work than needed but 1 main fix, this:
Code:
Dim ExternalIP As String = "Null"
Should be:
Code:
Dim ExternalIP As String
Or
Code:
Dim ExternalIP As String = ""
Or
Code:
Dim ExternalIP As String = null



RE: [VB.NET] Getting your own IP - Killpot - 10-27-2015

(10-27-2015, 03:02 AM)respect Wrote:
(10-26-2015, 08:37 AM)Distance Wrote: getting your own ip in vb.net 

Code:
Private Function GetMyIP()         Dim ExternalIP As String = "Null"           Try             ExternalIP = (New WebClient()).DownloadString("http://checkip.dyndns.org/")             ExternalIP = (New Regex("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) _                          .Matches(ExternalIP)(0).ToString()         Catch exc As Exception             ExternalIP = "Null"         End Try           Return ExternalIP End Function

Way more work than needed but 1 main fix, this:
Code:
Dim ExternalIP As String = "Null"
Should be:
Code:
Dim ExternalIP As String
Or
Code:
Dim ExternalIP As String = ""
Or
Code:
Dim ExternalIP As String = null

there's no such thing as "null" in vb.net, VBNull is optional, but will return the Int 1 if it's returned in a function. Also, setting a string to "" is a bad habit, use String.Empty. Also, if this is all you've found you should look deeper, the error handling is terrible, its worthless. He should be doing other things than just setting the IP to "null", show a messagebox with the error, maybe have custom error handling etc.


RE: [VB.NET] Getting your own IP - Fusion - 10-27-2015

I would make this a string (C# public string getIP()) and return the IP so you can call it like (C# string ip = getIP()Wink idk VB.gay


RE: [VB.NET] Getting your own IP - ɘxɘ - 10-27-2015

(10-27-2015, 03:39 AM)Killpot Wrote:
(10-27-2015, 03:02 AM)respect Wrote:
(10-26-2015, 08:37 AM)Distance Wrote: getting your own ip in vb.net 

Code:
Private Function GetMyIP()         Dim ExternalIP As String = "Null"           Try             ExternalIP = (New WebClient()).DownloadString("http://checkip.dyndns.org/")             ExternalIP = (New Regex("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) _                          .Matches(ExternalIP)(0).ToString()         Catch exc As Exception             ExternalIP = "Null"         End Try           Return ExternalIP End Function

Way more work than needed but 1 main fix, this:
Code:
Dim ExternalIP As String = "Null"
Should be:
Code:
Dim ExternalIP As String
Or
Code:
Dim ExternalIP As String = ""
Or
Code:
Dim ExternalIP As String = null

there's no such thing as "null" in vb.net, VBNull is optional, but will return the Int 1 if it's returned in a function. Also, setting a string to "" is a bad habit, use String.Empty. Also, if this is all you've found you should look deeper, the error handling is terrible, its worthless. He should be doing other things than just setting the IP to "null", show a messagebox with the error, maybe have custom error handling etc.

My bad I was thinking of something else. But the others would be better.