Results 1 to 2 of 2
  1. #1
    abhijeet_152 is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default IPAddress or HostName

    Can I use a Java API to verify whether a String is IPAddress or HostName.

    InetAddress.getByName(str) will return an Inet Address for both IPAddress and hostname.

    InetAddress.getByAddress(byte[]) requires the IPAddress in a Byte format. How to convert an IP String to this Byte Array ? A simple String.toByteArray() does not yield the correct result.

    Inet6Address has a function called textToNumericFormat(String) that returns a Byte Array but this method is hidden and API users cant use them.

    Please help !! Thanks in advance...

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Rep Power

    Default Example...

    Does the last example in the link help?

    InetAddress examples


    • Credits according to the header:

    Java Network Programming, Second Edition
    Merlin Hughes, Michael Shoffner, Derek Hamner
    Manning Publications Company; ISBN 188477749X
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Replies: 3
    Last Post: 07-25-2011, 04:19 PM
  2. Get the IP address&hostname of the host from the LANs
    By linux0kernel in forum Networking
    Replies: 3
    Last Post: 10-16-2008, 02:43 PM
  3. How to track client logout time and orignal ipaddress (not gateway) in java
    By psandeep in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-13-2008, 01:32 AM
  4. IP to HostName
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-11-2007, 09:07 PM

Posting Permissions

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