Using inetaddress to find host names

I am currently writing a java program in which I need to capture the ip address of the client machine in which the browser is running. I know I can do this, but how can I find the host name associated with this ip address. If I run the code below, I receive the host name on some machines, but others I get the ip address returned.
I only want to allow people to use my site that have a valid host name. Any suggestions?
Code:
import java.net.*;
public class iplookup {
public static void main(String[] args) {
     try {
          System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
          String test1 = args [0];
          InetAddress local = InetAddress.getByName(args[0]);
          System.out.println("Host Address = " + local.getHostAddress());
          System.out.println("Host Name = " + local.getHostName());
          System.out.println("Host Canonical Name = " + local.getCanonicalHostName());
          System.out.println("args = " + test1);
          String test2 = local.getHostAddress().toString();
          if (test1 == test2) {
               System.out.println("bad address");
     catch(Exception e) {
          System.out.println("bad address");
          e.printStackTrace();
}

Thanks for the help! I am trying to use the conditional statement to
check if the ipaddress has an associated host name. I am finding that if the ip address does not have a hostname, the method getHostName returns the ipaddress. I am using this logic to filter out ipaddress that do not have a host name associated with it. I understand that I will receive an exception if an ipaddress is not a valid ipaddress. But I also want to make sure that the ip has an associated hostname.
Is my assumption correct?

Similar Messages

  • Find host name and port number using query

    Hi,
    How do find the system_name, host_name and port no
    using sql query or data dictionary.
    plz

    SELECT i.instance_name, i.host_name, f.release_name RELEASE, i.version, k.patch_level FROM
    v$instance i, fnd_product_groups f, fnd_product_installations k WHERE
    UPPER(SUBSTR(i.instance_name, 1, 4)) = UPPER(SUBSTR(f.applications_system_name, 1, 4)) AND
    k.application_id = '200';

  • Re: Find Host Name thru Forte

    At 1:42 PM 5/21/96, <@ig4.att.att.com:[email protected]> wrote:
    Hi,
    What is best way to find Hostname under forte on Solaris 2.X platform
    within Forte?
    Thanks in advance,
    [email protected]
    one quick way would be to issue a RunCommand with the command 'hostname',
    capture the output in a file or memory stream and read it. RunCommand
    is on partition or operatingsystem class - do a search on it.
    operatingsystem or partition may also have a command to get the node name,
    though this is not necessarily the hostname.
    -John
    John Jamison
    Engineering Manager
    Sage Solutions, Inc.
    [email protected]
    (415) 392-7243 x508
    fax: (415) 392-4030
    http://www.sagesoln.com/sage.html

    Actually, Forte provides this info in an attribute call:
    task.Part.OperatingSystem.NodeName
    This is in the OperatingSystem class of the Framework Library.
    There are other interesting information about the running env.
    Lee Wei
    >
    At 1:42 PM 5/21/96, <@ig4.att.att.com:[email protected]> wrote:
    Hi,
    What is best way to find Hostname under forte on Solaris 2.X platform
    within Forte?
    Thanks in advance,
    [email protected]
    one quick way would be to issue a RunCommand with the command 'hostname',
    capture the output in a file or memory stream and read it. RunCommand
    is on partition or operatingsystem class - do a search on it.
    operatingsystem or partition may also have a command to get the node name,
    though this is not necessarily the hostname.
    -John
    John Jamison
    Engineering Manager
    Sage Solutions, Inc.
    [email protected]
    (415) 392-7243 x508
    fax: (415) 392-4030
    http://www.sagesoln.com/sage.html

  • Using internal and external host names

    I am trying to configure portal to work with machines in the internal network and outside world. Is there a way to do it?
    Dolf-Jan
    null

    Dolf-Jan,
    To add additional aliases that the portal and login server will recognize, add the new alias as a new Partner Application on the login server, and then use the 3 parameters that it generates (site id, site token, encryption key) - to invoke the ssodatax script, located in the ORACLE_HOME/portal30/admin/plsql directory (if you're using the Early Adopter Release, replace "portal30" with "webdb30"). ssodatax is used to add multiple aliases on the portal side. Another script, ssodatan, is used to add a single alias for a new installation:
    ssodatan = sso data for New installation
    ssodatax = sso data for eXisting installation
    Run ssodatax with no parameters to see the calling syntax.
    To administer the login server, click on "Login Server Administration" under the "Administer" tab of the Portal administrator's home page.
    You will also need to configure the apache listener properties ServerName and NameVirtualHost for both hostnames.
    Regards,
    Jerry

  • Changing host name of JDI server

    Hi,
    during installation of JDI I used ip-addresses as host names for defining the domain host, the SLD server in domain definition, the dtr server URL in track definition, the CBS server URL in track definition.
    I know that one shouldn´t use ip-addresses at all but we did have some trouble with the network infrastructure (DNS-Server, ...) at the beginning and the start of the project couldn´t be delayed.
    Now, for any reason, the network department gave our server a new ip-address.
    I then opened the CMS configuration tool and tried to change the host names (this time not to ip-addresses because DNS-Server works properly in the meantime).
    Changing domain data is no problem. But when I try to save the changes of my track(s) I get an error message that says I should contact my administrator. I am the administrator
    My Questions:
    How is it possible to change the host names of JDI tracks?
    What is to do at client side? There are already some developers working with the dev. configurations. Is it sufficient to change the according entries in the .confdef file or do the clients have to donwload the new dev. configuration from CMS host?
    Thanks in advance
    Helmut

    Hello Helmut,
    it should be possible to change the host names for tracks. You can get more error message details in the trace file of the Engine. To do so connect to your engine with the J2EE Administration Tool  and check the defaultTrace.trc File in the Log Viewer.
    For more details how to find this trace information have look into the Change Management Server Problem Analysis Scenarios (Link: http://help.sap.com/saphelp_nw04/helpdata/en/81/4bce4016d28031e10000000a1550b0/frameset.htm). In the first Scenario Incorrect Initial CMS Configuration you can also find the general information how to read and find the CMS trace files.
    Please open a CSN message for the component BS-CTS-CMS if can not find the reason for the error message or if it is real problem in CMS.
    Best Regards, Michael

  • Finding file name

    Hi,
    I use this command "find . -name "*.html" | xargs cat | grep "searchCriteria" " to find string searchCriteria in any file having html as extension.
    I get the output searchCriteria if that string is in the file name.. But, what if I want to know the location of html file from which searchCriteria was displayed?
    Regards,

    The grep command does not need "cat":
    find . -iname "*.html" | xargs grep -i "Search Criteria"(match and search is also case insensitive)
    I get the output searchCriteria if that string is in the file name.. But, what if I want to know the location of html file from which searchCriteria was displayed?Not sure if I understand you here. Can you give an example?
    Edited by: Dude on Jul 1, 2011 1:18 AM

  • Are Wildcards possible for host name in "no proxy for" setting?

    Our LAN requires a proxy for internet access. I need to bypass proxy for certain host names, as the proxy blocks many ports.
    Things work if I enter the entire host name. But there are many, so I wish to use wildcards in the host name.
    That does not seem to work.

    There is no solution for host names and wild cards as far as I know. That is why I showed how to do this with the IP.
    Does it work if you only specify the top level domain if you want to include other domains with the same postfix?

  • I found my college roomates band's cd . how can i find track names since its not in database. they were semifamous so it should come up

    How can i use itunes to find track names on cds from an old roomate"s band. Its a professional cd that was sold in stores but it shows up as track 1 track two. the database could not find them.   
    I had another friend who made a cd and inputed all of the data but itunes still puts them as track 1 track two.  How can i find the names without manually putting them in?

    How can i find the names without manually putting them in?
    They will only show up in iTunes if someone (your friend, their producer, or a fan) has submitted them to Gracenote.
    If that did not happen, you can try identifying the tracks with an auto-tagging program such as Picard. 

  • Find current host name using Java

    I am running currently on Oracle 9i app server in a clustered environment. My application has business logic that needs current host name. How can I find out the host name without externalising(like properties file) the information. Is there a java api like
    .getHostName()
    Rama

    try this:
    import java.net.InetAddress;
    public class Foo {
        public static String getLocalhostName() {
            String hostName = "";
         try {
             InetAddress address =
              InetAddress.getLocalHost();
                hostName = address.getHostName();
            } catch (Exception e) {
                // error handle any which way you like
                e.printStackTrace (System.err);
            return hostName;
    }cheers,
    Georg.

  • Host-name - how do I find out which one to use ?

    Hello,
    Within a project I need to setup an MAC-OS-X server - since I am neither a network pro nor very familiar with MAC I am stuck with a quite simple question:
    In one of the first windows of the installation process (Mac OS-X 10.4.3) Server) I am asked to provide host-name, computername and rendezvous name.
    The computername is clear - but especially the hostname I don't know what to enter (the example given: www.domain.tld) does confuse me) but also what rules do apply for the rendezvous name ?. The server is not directly connected to the internet, it will be a dept. server within a university .
    I feel quite stupid asking for this but I can't afford wasting more time with this little thing. Thanks it advance for the help and patience with me.
      Mac OS X (10.4.3)  

    Unless your network is setup as an intranet, with a dns server resolving hostnames, you shouldn't need to worry about the hostname setting. As for rendezvous, it's usually in my experience, is the same as the computer name.
    Hope this helps.

  • What's the reason for this message, "A server with the specified host name could not be found" ? I'm using iPhone 4s, 16gB, iOS 7.0.4

    I get a pop-up message saying "A server with the specified host name could not be found", whenever I try to access any streaming websites/apps or even WhatApp over Wi-Fi and I cannot access the specific THING for that moment, and I've tried switching Wi-Fi On and Off both in my Phone and also in the Router. I got an internet connection and a Wi-Fi router just before two days, and it's happening since. I got the internet speed around 80kbps and i can easily stream YouTube videos except sometimes, I receive that annoying message. I can't even browse the internet in Safari, which says "No Internet Connection"(Even though the Wi-Fi is connected), and I can access it after somewhile (say 10 minutes, it'll be perfectly alright). I use iPhone 4s. And everything about the internet connection is totally fine in my Computer, but not in my iPhone, as I've explained the issues, above. If there are any technical settings that I should change/modify, either on my computer(Windows 7 OS) or in my iPhone(iOS 7.0.4), PLEASE let me know
    I hope I've provided enough information for the reader to understand my point. (I apologize for my verbal mistakes, if there are )
    THANKS

    Hello Paneesh,
    Thank you for the details of the issue you are experiencing with Wi-Fi on your iPhone 4s.  I recommend the following steps:
    Be sure you're in range of your Wi-Fi router (access point).
    Tap Settings > Wi-Fi and turn Wi-Fi off and on. If your W-Fi setting is dimmed, follow these steps.
    Confirm that your Wi-Fi router and cable or DSL modem are connected to power, turned on, and connected to the Internet. If not, refer to your network administrator or Internet service provider (ISP) for assistance.
    Restart your iOS device.
    Tap Settings > Wi-Fi and locate the Wi-Fi network to which you're connected.
    Tap and Forget this Network.
    Try to connect to your desired Wi-Fi network.
    Note: You may need to enter your Wi-Fi password again if your network requires one.
    Turn your Wi-Fi router off and on2. If your ISP also provides cable or phone service, check with them before attempting this step to avoid interruption of service.
    Update your device to the latest version of software.
    Update your Wi-Fi router to the latest firmware2. For AirPort Base Stations, install updates using the AirPort Utility.
    If the issue is still unresolved Wi-Fi disconnects or signal strength is less than expected
    Move closer to the Wi-Fi router (access point).
    Check for sources of potential interference.
    Remove any case, stand, or other accessories from your iOS device and see if signal strength improves.
    Reset network settings by tapping Settings > General > Reset > Reset Network Settings. Note: This will reset all network settings including
    previously connected Wi-Fi networks and passwords
    recently used Bluetooth accessories
    VPN and APN settings
    You can find the full article here:
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/ts1398
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Problem. Help please. Server Host Name "already used"

    Hello.
    This isn't very critical. But I'm getting a little tired.
    For some reason, from time to time, it appears the following message:
    "The server host name '[my nameXX]' is already being used. It has been substituted by [my_nameXX+1]".
    So it keeps incrementing by 1 that index next to the name of the computer...
    It seems like the name of the computer stays somehow in the net, in the router or in itself, and when I restart my MacBook, it finds that the name is already used.
    Any idea??
    Thanks in advance

    Hola ElPiter, y una cálida bienvenida a los foros!
    The last time I saw this I think it was the Router or Server doing it.
    Does everything have the latest Firmware updates? Routers in particulasr can't be trusted for any Auto update/notification of Firmware.

  • X11vnc: cannot use host name in Windows

    Hi, i cannot find my host name if i start x11vnc. It works if i write on Windows XP "Real VNC Viewer" IP adress. When i start x11vnc
    The VNC desktop is: asus:0
    But if i write to Real VNC Viewer "asus" or "asus:5900", it doesn't work but if i write "192.168.1.101" it works fine. I need find how i can use host name, because i have DHCP on router and IP address will be different. Please help, thanks

    Well, that's to be expected with standard plastic routers, or can you ping your XP box by name, for example?
    Look in your router interface if you can specify DHCP leases with fixed IPs, depending on MAC address.
    And then specify hostnames for those IPs in /etc/hosts and c:\windows\system32\drivers\etc\hosts

  • HT201320 I have an email account through yahoo. I am having trouble setting it upon my iPhone and can't receive or send emails!!!! I contacted Rogers and they said I need to find out the host name of the incoming server, in other words yahoos host name. H

    I have an email account through yahoo. I am having trouble setting it upon my iPhone and can't receive or send emails!!!! I contacted Rogers and they said I need to find out the host name of the incoming server, in other words yahoos host name. Help!!

    Yahoo's servers are notoriously unreliable. Use the "Yahoo" account type when setting it up. If it doesn't work, and you are positive the credentials are correct, wait a while and try again.
    While you're waiting, set up a free gmail or iCloud email account.

  • My iMac can not see my mini Mac via Airport extreme using host name, only via IP address. What am I doing wrong ?

    I have an iMac and a mini Mac attached to the same Airport extreme. It would appear that Bonjour works because I can see the hostname of the mini Mac server in Finder on the iMac.
    But if I type in the host name (myminimac.private) in the Safari browser at the iMac it can not find the mini mac. However if I type in the IP address of the mini mac server it can see the see it.
    It used to work but I must have done something to mess it up.
    Anybody any suggestions ?

    You have the wrong card. You need the original AirPort card for your G4.
    ...how the **** do i get the Superdrive to open up so i can put in a CD/DVD?
    If the keyboard has a media eject key, press that. If not, hold down F12.

Maybe you are looking for