Finding phone's IP?

XHorntail

New Member
I want to pull my IP into a variable. The Network library's GetIP looks like it only finds the IP of known sources, I just want my own external IP (localhost, but externally connectable.) The idea is to pull my IP, and send it in an SMS. Also, does the network library work for EVDO internet, or just WiFi? Could just test that, but figured I'd ask while I'm here.

I look foward to working with everyone here!

PS
The 3 character search limit is a bummer :( Can't search words like IP.
 

XHorntail

New Member
Ok, solved it! Uses both server and client objects, code posted below for any future reference!

B4X:
Sub Globals
   Dim sIP(0) As String
End Sub

Sub App_Start
   Form1.Show
   Server.New1(50000)
   Client.New1
   sName = Server.HostName
   sIP() = Client.GetIp(sName)
   
   For i = 0 To ArrayLen (IP()) - 1
                 sIP2 = IP(i)
   Next

   Label1.Text = "Computer IP: " & sIP2 'As per my results, the last value is the external IP
                            'If it results in an internal IP, your device is likely offline.

End Sub
Thid code hasn't been tested as typed, so please excuse any typo's.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
You should use something like:
B4X:
Sub Globals
    'Declare the global variables here.
    Dim ip(0)
End Sub

Sub App_Start
    server.New1(0)
    client.New1
    ip() = client.GetIP(server.HostName)
    For i = 0 To ArrayLen(ip())-1
        Msgbox(ip(0))
    Next
End Sub
The Network library should work with any reliable connection.

I agree about the three characters search limit. If I remember correctly it is a limitation of the forum software.
 

XHorntail

New Member
Your solution is pretty close to mine! Thanks for the input! I didn't realise the Network Server Object could be instantiated with a Null port, good to know!

I have to say, this is one of the best non-microsoft IDE I've used, especially at it's price bracket!
 
Top