Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: How to give ip address as a input on java...if I give ip addrees as a input need to display ip adress present in the server or not??? Date: Wed, 13 Jun 2018 11:06:08 -0500 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 13 Jun 2018 16:06:08 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="0a9b75572db03bf22ee48251f63a437e"; logging-data="5523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OqEGRq+OSDaDwq7E5CQct" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:KS+16POpl3uOx6XzISP0YpkSMDI= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:38370 On 6/13/2018 11:01, Knute Johnson wrote: > On 6/13/2018 05:39, siddareddy.moolam@gmail.com wrote: >>   i have tried in java : >> >> package com.techstar.com; >> >> import java.net.InetAddress; >> import java.net.UnknownHostException; >> >> class IpAdress{ >> >> public static void main (String args[]) throws UnknownHostException { >> >> >> //  strIp containing an IP address or a machine name >> //  strServer containing a machine name >> >> // Get the IP address to look for as InetAddress >> >>      String strIp = "192.168.15.74"; >> InetAddress ip = InetAddress.getByName(strIp); >> String strServer=""; >> // Get all IP adresses associated with strServer >> InetAddress[] serverIps = InetAddress.getAllByName(strServer); >> for (int i = 0; i < serverIps.length; i++) >> { >>      if (ip.equals(serverIps[i])) >>      { >>          System.out.println("Server ip is present" +ip); >>      } >>      else { >>          System.out.println(" ip is not present" +ip); >>      } >>      } >> }} >> > > Probably the easiest way is to try to connect to the server. > You could also look at InetAddress::isReachable -- Knute Johnson