Results 1 to 6 of 6

Thread: ip address of client bound to a ServerSocket?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    ip address of client bound to a ServerSocket?

    Anybody have a clue how to do this? I need to get the ip address of the host that is bound to a ServerSocket so i can make a DNS check to resolve the client.
    Code:
    ServerSocket ser = new ServerSocket(13);
    
    System.out.println(ser.getInetAddress().getHostName(???));

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    How about the getHostAddress() method of InetAddress?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Posted by crptcblade

    How about the getHostAddress() method of InetAddress?
    That would almost be the equivalent to what i already have except instead of getting the host name and the ip address using getHostAddress() would just give me the ip address.

    The problem i am having is when i use the getInetAddress() method from the ServerSocket class it returns a InetAddress object initialized with an ip address of 0.0.0.0.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you do a netstat, you'll find that all generic listener sockets are shown with a 0.0.0.0 IP address. Only the sockets that actually communicate with a client are bound to an IP.

    Why exactly do you want to do this? To find our your own server name?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Ill most likely have to get a handle to the connected Socket via ServerSockets accept() method and then query the socket for the ip address.

  6. #6

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Posted by CornedBee

    Why exactly do you want to do this? To find our your own server name?
    No i want to find the ip address of the clients that are bound to the systems ports.

Posting Permissions

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



Click Here to Expand Forum to Full Width