# Ketai library, KetaiNet.getIP(); Error

**URL:** <https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415>\
**Category:** Processing for Android\
**Created:** [May 20, 2019, 11:04am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415 "2019-05-20T11:04:19Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 20, 2019, 11:04am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/1 "2019-05-20T11:04:19Z")

</div>

Hi. ketai library related.

> import ketai.net.wifidirect._;  
> import [ketai.net](http://ketai.net)._;  
> import ketai.ui.\*;
> 
> KetaiNet.getIP();

KetaiNet.getIP (); The function does not work properly.  
It does not get the correct IP address value.

Android version 8.0: works fine  
Android version 9.0: Strange IP address

Is there any way to solve it?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 22, 2019, 12:44pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/2 "2019-05-22T12:44:07Z")

</div>

@GWAK ===  
can you put the code you are using?  
can you put the console error message (if it exists)?  
what do you mean by Android version? - Is it compiling with or running on a device with 8 or 9?  
how is your Manifest?

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 22, 2019, 3:42pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/3 "2019-05-22T15:42:48Z")

</div>

@akenaton

Are you an angel?  
Thank you for your kind answers.

 ![tt](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5f68962d98ef49cdf63a308a904b6e6a7869b7de.jpeg)

> import android.os.Bundle;
> 
> import [ketai.net](http://ketai.net)._;  
> import ketai.ui._;  
> import oscP5._;  
> import netP5._;  
> void setup()  
> {  
> fullScreen();  
> orientation(PORTRAIT);  
> println(KetaiNet.getIP());  
> }

Please take a look at the picture of the hardware.  
The Wi-Fi module constitutes the network and the smart phone is connected.  
(picture)The current IP address is the IP address given on the actual network.

(source code result : )  
Smartphone Android version 6.0 ~ 8.0: 192.168.4.2  
Smartphone Android version 9.0: 192.0.0.5

The cause of the phenomenon seems to be the phenomenon after updating the Android version.

I would like to know IP address(smartphone) at the moment. Is there a way?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [May 22, 2019, 3:47pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/4 "2019-05-22T15:47:31Z")

</div>

> [@GWAK](#):
>
> It does not get the correct IP address value.

What value do you get? “0.0.0.0”

How are you setting up to use ver 9? Is that through your manifest?  
I confirm it works in ver 8 (Api 26 (?) ) and I enabled internet and access\_network\_state. I might only need one of them as i did not check the docs.

Kf

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 22, 2019, 4:04pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/5 "2019-05-22T16:04:16Z")

</div>

@kfrajer

I use android version 9.0  
Permissions :

1. ACCESS\_NEXWORK\_STATE
2. ACCESS\_WIFI\_STATE
3. INTERNET

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 22, 2019, 4:34pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/6 "2019-05-22T16:34:56Z")

</div>

@GWAK ===  
so you are running this code on a device with android 9 installed. Now, what about your Manifest?Is uour SDK updated to this API ?

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 22, 2019, 10:41pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/7 "2019-05-22T22:41:19Z")

</div>

@akenaton, @kfrajer

Dear akenaton, kfrajer

Example1)  
target SDK : API9 / Smartphone Android 9.0 :: Strange value ip address

Example2)  
target SDK : API9 / Smartphone Android 8.0 :: Correct ip address

Example3)  
target SDK : API8.1 / Smartphone Android 9.0 :: Strange value ip address

Example4)  
target SDK : API7.0 / Smartphone Android 9.0 :: Strange value ip address

in conclusion,

I think it’s a fatal error on Android version 9.0(Smart Phone).  
Do not you guys do that, too?

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 22, 2019, 11:01pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/8 "2019-05-22T23:01:46Z")

</div>

I solved it.

Source code

> ```
> if (!inetAddress.isLoopbackAddress()
> && thing == "0.0.0.0"
> && inetAddress.getHostAddress().matches(
> "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
> thing = inetAddress.getHostAddress();
> }
> 
> ```

Corrected source code

> ```
> if (!inetAddress.isLoopbackAddress()
> // && thing == "0.0.0.0"
> && inetAddress.getHostAddress().matches(
> "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
> thing = inetAddress.getHostAddress();
> }
> 
> ```

It seems to be a bug since it was version 9.0 of Android.  
Anyhow, commenting like that is done.

thank you.

![tt](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fdcff4953b2c298264c0b4ec4c616de054a45bb4.jpeg)

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [May 23, 2019, 6:12am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/9 "2019-05-23T06:12:35Z")

</div>

Based on this [https://stackoverflow.com/a/10199498/7229333](https://stackoverflow.com/a/10199498/7229333)

There must be a reason for that comparison there that you are commenting out. With your suggested change, I would recommend the next additional change so from:

```auto
thing = inetAddress.getHostAddress();

```

to

```auto
return inetAddress.getHostAddress();

```

Kf

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 23, 2019, 11:35am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/10 "2019-05-23T11:35:42Z")

</div>

@kfrajer@GWAK

happy that it works but i remain very confused:

i never saw the Manifest  
i suppose that @GWAK is using 2 or 3 phones (6,8,9)  
i dont know what is the compiling version  
i would like to read some complete code snippet  
i have had a look at the src code from Ketai (from which is extracted the code posted) and String “thing” is set to “0.0.0.0” in a for loop (at each loop) so i cannot see why commenting it can change something…And it “returns” the ip, as suggested by @kfrajer

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 23, 2019, 3:29pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/11 "2019-05-23T15:29:15Z")

</div>

@akenaton

This is ‘Ketai library source code’.

> static public String getIP() {  
> String thing = “0.0.0.0”;
> 
> ```
> 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()
> && thing == "0.0.0.0"
> && inetAddress.getHostAddress().matches(
> "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
> thing = inetAddress.getHostAddress();
> }
> PApplet.println("IP address: " + inetAddress.getHostAddress());
> PApplet.println("thing : " + thing);
> }
> }
> } catch (SocketException ex) {
> PApplet.println("SocketException:" + ex.toString());
> } catch (NullPointerException nx) {
> PApplet.println("Failed to get any network interfaces...");
> }
> 
> //PApplet.println("IP address: " + inetAddress.getHostAddress());
> //PApplet.println("thing : " + thing);
> return thing;
> 
> ```
> 
> }

The source code has been modified as shown below.

> // && thing == “0.0.0.0”

I do not know the exact reason. ;;  
The obvious thing is that there is an error in the Android 9.0 version of the smartphone.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 23, 2019, 3:37pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/12 "2019-05-23T15:37:20Z")

</div>

@GWAK ===  
i told you that i have had a look to this code (from the ketai lib src) ; but you dont answer to the others questions and the real explanation is probably here (the Manifest, the version used for compiling and so on…+ the real code you are using ) -

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 24, 2019, 12:12am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/13 "2019-05-24T00:12:05Z")

</div>

@akenaton

Dear akenaton,

**[Use source code / Real code]**

> import android.os.Bundle;
> 
> import [ketai.net](http://ketai.net/). _;  
> import ketai.ui._ ;  
> import oscP5. _;  
> import netP5._ ;  
> void setup()  
> {  
> fullScreen();  
> orientation(PORTRAIT);  
> println(KetaiNet.getIP());  
> }

**[Result]**  
Example1)  
target SDK(Manifest Version) : API9 / Smartphone Android 9.0 :: Strange value ip address

Example2)  
target SDK(Manifest Version) : API9 / Smartphone Android 8.0 :: Correct ip address

Example3)  
target SDK(Manifest Version) : API8.1 / Smartphone Android 9.0 :: Strange value ip address

Example4)  
target SDK(Manifest Version) : API7.0 / Smartphone Android 9.0 :: Strange value ip address

Do you understand?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 24, 2019, 8:53am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/14 "2019-05-24T08:53:17Z")

</div>

@GWAK ===  
not sure to understand:

- are you using 2 real phones (8,9) for testing?
- when you commented: thing = “0.0.0.0” how have you done that?Recompiling the library?

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [June 8, 2019, 12:19am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/15 "2019-06-08T00:19:53Z")

</div>

@akenaton

Hi, Dear akenaton.

1. Yes, real testing.
2. I did not create a library, I used only that source.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [June 8, 2019, 7:14am UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/16 "2019-06-08T07:14:04Z")

</div>

@GWAK ===

-Real testing WITH TWO REAL DIFFERENT PHONES?

- Where and how have you used that source? - I cannot see it in the real code you have put

-without recompiling the lib commenting/uncommenting the src code cannot have any effect!

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 4, 2023, 11:22pm UTC](https://discourse.processing.org/t/ketai-library-ketainet-getip-error/11415/17 "2023-04-04T23:22:55Z")

</div>

@akenaton

> **[KETAI\_GETIP.zip](https://drive.google.com/file/d/1nz4t95nvHehr_AHeXuoWafa-so5jE5e6/view?usp=sharing)**
>
> Google Drive file.

Depending on the Android version, the result value is different.
