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: Thu, 14 Jun 2018 13:02:50 -0500 Organization: A noiseless patient Spider Lines: 56 Message-ID: References: <08c836c0-5014-4e7d-8dab-ddf99059e9c7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 14 Jun 2018 18:02:51 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="4da6910254446a5a30b58f5e231b88ad"; logging-data="9193"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PZp6dDljAkjdjZ6ASZ7/U" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:B4uVT51fJ6ceUO5GEjxA/jqbM1s= In-Reply-To: <08c836c0-5014-4e7d-8dab-ddf99059e9c7@googlegroups.com> Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:38378 On 6/14/2018 01:14, siddareddy.moolam@gmail.com wrote: > On Wednesday, 13 June 2018 21:31:40 UTC+5:30, 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. >> >> -- >> >> Knute Johnson > > i need to also check whether the ip is up or down ??? > InetAddress::isReachable is just a ping and only tells you the machine is there and responding to pings. Connecting to the server tells you the machine is there and the server is running. -- Knute Johnson