Showing IP address of my device in the network?

Hello,

I want to send data from one to another device by using the oscp5 library. Is there a function that returns the IP address of my device in the network? For example: The address of my notebook is 192.168.178.25.

Thank you for your help!

Answers

  • I'd start by googling "Java get ip address" for a ton of results.

  • I've already done that but I don't know how to realize it in Processing.

  • Processing is built on top of Java. Anything you can do in Java, you can do in Processing.

  • All the results don't work. Maybe you have a link to an example that does work? I am a beginner in programming netzwork communication.

  • What have you tried? What exactly isn't working for you?

  • Cool, and what happened when you tried that?

  • I could not even run the programm because there are error messages like "Error on "VariableDeclarators"" or "The class "inetAddress" does not exist".

  • Sounds like you're missing import statements.

  • In this example there weren't any lines to import something. Could you please try one of these examples in order to check if it really works? Or do you even have a sketch that already works?

  • Thank you. Now it tells me the IP address of the Server (192.168.137.1). But I need to know the address of my device which is 192.168.178.25. How do I get this done?

  • Ok, your question is how to get the ip address of the device that you want to connect to? The idea is that the server listens, and the client connects to this server. The client needs to know what server to connect to aka. its IP address. You should provide more details of what you are trying to do because working with scarce details leads to an inefficient use of this forum....

    Kf

  • I think you misunderstood me. I want to have a server with a permanent IP-address (settings in my router). Now I will connect clients to it which don't have a permanent IP-address (So the server doesn't know where to send data). Because of that problem every client has to send his IP-address (in my home network) to the server while starting. That's why I need to know how to get the address. I hope I am on the right way of solving my problem.

  • Can't you answer my question yourself instead of just posting a link? Apart from that these questions do not have to do anything with my problem because I want to run server and client in the same network - not over the internet. I just wanted to know how to get the IP of my device. Isn't there anybody who can post a little example code?

  • edited December 2017 Answer ✓

    https://Docs.Oracle.com/javase/8/docs/api/java/net/InetAddress.html

    /**
     * Find LAN IP (v1.1)
     * GoToLoop (2017/Dec/23)
     *
     * Forum.Processing.org/two/discussion/25681/
     * showing-ip-address-of-my-device-in-the-network#Item_17
     *
     * Docs.Oracle.com/javase/8/docs/api/java/net/InetAddress.html
     */
    
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    
    static final String LOCAL_IP = findLanIp();
    
    void setup() {
      println(LOCAL_IP);
      exit();
    }
    
    static final String findLanIp() {
      try {
        return InetAddress.getLocalHost().getHostAddress();
      }
      catch (final UnknownHostException notFound) {
        System.err.println("No LAN IP found!");
        return "";
      }
    }
    
  • edited December 2017
    """
     Find LAN IP (v1.1)
     GoToLoop (2017/Dec/23)
    
     https://Forum.Processing.org/two/discussion/25681/
     showing-ip-address-of-my-device-in-the-network#Item_18
    
     https://Docs.Oracle.com/javase/8/docs/api/java/net/InetAddress.html
    """
    
    from java.net import InetAddress
    
    def findLanIp(): return InetAddress.getLocalHost().hostAddress
    
    LOCAL_IP = findLanIp()
    
    def setup():
        print LOCAL_IP
        exit()
    
Sign In or Register to comment.