Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get "real" IP address with VB.NET?

Tags:

vb.net

ip

I'm looking for a function that will give me my real IP, not my local IP. the function i currently have, returns the ip in network and sharing center which is 192.168.2.100 But if I go to whatismyip, then it gives my real IP.

How could I get this using VB.NET? thanks

like image 549
jmasterx Avatar asked Dec 23 '22 09:12

jmasterx


1 Answers

To Combine the answers above" Create a php file and paste this in it:

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

save it as curip.php and upload it to your server.

In your VB.net project create a module. Declare the imports section at the very top

Imports System.Net
Imports System.IO

And create your function:

    Public Function GetIP() As String

    Dim uri_val As New Uri("http://yourdomain.com/curip.php")
    Dim request As HttpWebRequest = HttpWebRequest.Create(uri_val)

    request.Method = WebRequestMethods.Http.Get

    Dim response As HttpWebResponse = request.GetResponse()
    Dim reader As New StreamReader(response.GetResponseStream())
    Dim myIP As String = reader.ReadToEnd()

    response.Close()

    Return myIP
End Function

Now anywhere in your code you can issue

Dim myIP = GetIP()

as use the value from there as you wish.

like image 159
shaiss Avatar answered Jan 18 '23 11:01

shaiss