How can I get local IP with App inventor 2?

4,435 views
Skip to first unread message

Marius Dege

unread,
Dec 19, 2015, 4:31:22 PM12/19/15
to MIT App Inventor Forum

Hello,

did somebody know, if I could get my local IP adress of my smartphone with App Inventor 2?

Taifun

unread,
Dec 20, 2015, 8:53:42 AM12/20/15
to MIT App Inventor Forum
you could write your own extension and create a block yourself...

however that will be more advanced and will require some Java skills...

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by  Taifun.

Marius Dege

unread,
Dec 20, 2015, 4:10:25 PM12/20/15
to MIT App Inventor Forum
Hello,

did you send some pictures? The won't displayed.

I'm from germany, it's not so easy for me to check this from ai2, because everything is on englisch.
I would apreaciate, if you could explain sth. for me.

Could I wirte everthing for the blocks, or is this limited by sth (i thing eg. a tcp connection for the web-interface (this time, it's only http-put and get)
And I need a function/block, that gives me the local ip from the device.

could you tell me, if I could make that (with lan ip it's really important for me).

Other Question: Must I import my projects, where I want to use that extension, to the http://extension-test.appinventor.mit.edu/ ?

Thanks a lot for answers!

spider pig

unread,
Dec 20, 2015, 5:00:21 PM12/20/15
to mitappinv...@googlegroups.com

If you want your public ip, you can do that with a web component (in the blocks view under connectivity/Web). Here is an example


Message has been deleted

Marius Dege

unread,
Dec 20, 2015, 5:15:32 PM12/20/15
to MIT App Inventor Forum
Hello spider pig,

that's good, but I wanna have the LOCAL IP (the IP from my home network, and not the web ip).

spider pig

unread,
Dec 20, 2015, 5:21:56 PM12/20/15
to MIT App Inventor Forum
You could use the same strategy if you run a server somewhere in your home network that sends back your ip. But I wonder why you need that ip anyway?

Marius Dege

unread,
Dec 20, 2015, 5:32:20 PM12/20/15
to MIT App Inventor Forum
Hello Taifun,

here's a code example to get local ip, okay, and now? How can I get with that an aix extension?


 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public String getLocalIpAddress(){
   try {
       for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();  
       en.hasMoreElements();) {
       NetworkInterface intf = en.nextElement();
           for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
           InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                return inetAddress.getHostAddress().toString();
                }
           }
       }
       } catch (Exception ex) {
          Log.e("IP Address", ex.toString());
      }
      return null;
}

Marius Dege

unread,
Dec 20, 2015, 8:17:24 PM12/20/15
to MIT App Inventor Forum
Hello,

this is not possible, because I build a device, wich you can control via WLAN with my App from App-Inventor.
I need the ip, to check, which router level I have (eg 192.168.x.203), so I need the x for the static ip from the device to control. I want to make that automaticly, not with a switch.
Why I can't make a webserver? I have build 3 devices, 1 for me, 1 for my girl and one for a friend. That's not practicable to make that by my "customers" :D I wan't to make a autonom running system.
They got my device, download my app via google Play and ready.

Taifun

unread,
Dec 22, 2015, 12:26:09 PM12/22/15
to MIT App Inventor Forum
you can get the local IP address now using my new WiFi extension
there are also some more useful blocks available there...

for more information see here https://puravidaapps.com/wifi.php

Thank you Marius for being the sponsor of the LocalIP block!


Taifun
Reply all
Reply to author
Forward
0 new messages