×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    34

    What is the best way to find out your IP address?

    I have a Nokia 9500 and want to find out what my IP address is. I wrote this piece of code on and it runs on the emulator (and gives me the correct IP),but only gives me 127.0.0.1 on the phone. I suspect that since the PC is "always on", that the server socket has available to it the IP address before you do an 'serverSocket.acceptAndOpen()'. Is this true?

    By the way, I don't really want to do an serverSocket.acceptAndOpen(), because I have no intention of ever connecting to that port, I just want to find out what my IP is.

    Cam

    public static String getIP() {

    String returnValue = "";
    ServerSocketConnection socket = null;
    try {
    socket = (ServerSocketConnection) Connector.open("socket://:",Connector.READ_WRITE,false);
    if (socket == null) {
    System.out.println("Socket is Null");
    System.exit( -1);
    }
    System.out.println("3");
    returnValue = socket.getLocalAddress();
    System.out.println("Return Value: " + returnValue);
    socket.close();
    } catch (IOException ex) {
    System.out.println("Exception raised by Network.getIP()");
    ex.printStackTrace();
    } finally {
    try {
    if (socket != null) {
    socket.close();
    }
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }
    return returnValue;
    }
    }

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,553

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    34

    Re: What is the best way to find out your IP address?

    Thanks for the info, unfortunately it is all based on C++ calls. Is there anything in Java that is similar?

    Cam

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    34

    Re: What is the best way to find out your IP address?

    I took a look at the C++ code and got a similar piece of Java code to compile but I keep getting the exception

    "Exception: Target port denied to untrusted applications"

    I've used port 80,8082 and 8080 and am loathe to start 'guessing' which ports are trusted or not. I suspect that all of them are are 'denied'.

    The code is as follows. I attached the permissions
    javax.microedition.io.Connector.serversocket, javax.microedition.io.Connector.socket, javax.microedition.io.Connector.datagramreceiver, javax.microedition.io.Connector.datagram, javax.microedition.io.Connector.comm, javax.microedition.io.Connector.http

    to the .jad file. Probably overkill but what the heck.


    import javax.microedition.io.Connector;
    import javax.microedition.io.SocketConnection;

    /**
    * @author croe
    *
    */
    public class NetworkSimple {

    public static String getIP() {
    String localhost = null;
    System.out.println("NetworkSimple.getIP()");
    try {
    SocketConnection socket = (SocketConnection) Connector
    .open("socket://www.symbian.com:8080");
    localhost = socket.getLocalAddress();
    System.out.println("Address of local host is " + localhost);
    socket.close();
    } catch (Exception e) {
    System.out.println("Exception: " + e.getMessage());
    }
    return localhost;
    }
    }

Similar Threads

  1. Replies: 1
    Last Post: 2004-04-05, 13:22
  2. Aphanumeric Address formats on MM1?
    By shtobias in forum General Messaging
    Replies: 0
    Last Post: 2003-09-09, 07:49
  3. Help! Help! My IP address is changing like crazy !!
    By jwynn_in_nh in forum Mobile Java General
    Replies: 0
    Last Post: 2003-07-22, 22:10
  4. How to find that mms recepient address belongs to External MMSE
    By parul_patidar in forum General Messaging
    Replies: 5
    Last Post: 2003-05-17, 21:43
  5. Sample Program to find Bluetooth Device Address
    By raymondyau in forum Bluetooth Technology
    Replies: 1
    Last Post: 2002-09-09, 07:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×