Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38368 > unrolled thread
| Started by | siddareddy.moolam@gmail.com |
|---|---|
| First post | 2018-06-13 03:39 -0700 |
| Last post | 2018-06-13 23:16 -0700 |
| Articles | 8 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
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??? siddareddy.moolam@gmail.com - 2018-06-13 03:39 -0700
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??? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2018-06-13 11:01 -0500
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??? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2018-06-13 11:06 -0500
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??? siddareddy.moolam@gmail.com - 2018-06-13 23:14 -0700
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??? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2018-06-14 13:02 -0500
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??? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-14 14:09 -0400
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??? Martin Gregorie <martin@mydomain.invalid> - 2018-06-14 21:40 +0000
i need to check whether particular ip adress is up or down can anybody help me?? siddareddy.moolam@gmail.com - 2018-06-13 23:16 -0700
| From | siddareddy.moolam@gmail.com |
|---|---|
| Date | 2018-06-13 03:39 -0700 |
| Subject | 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??? |
| Message-ID | <f1d70a92-e43f-4065-8c03-1bcb8782d737@googlegroups.com> |
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);
}
}
}}
[toc] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2018-06-13 11:01 -0500 |
| 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??? |
| Message-ID | <pfrf4m$3i9$1@dont-email.me> |
| In reply to | #38368 |
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
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2018-06-13 11:06 -0500 |
| 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??? |
| Message-ID | <pfrfdg$5cj$1@dont-email.me> |
| In reply to | #38369 |
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
[toc] | [prev] | [next] | [standalone]
| From | siddareddy.moolam@gmail.com |
|---|---|
| Date | 2018-06-13 23:14 -0700 |
| 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??? |
| Message-ID | <08c836c0-5014-4e7d-8dab-ddf99059e9c7@googlegroups.com> |
| In reply to | #38369 |
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 ???
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2018-06-14 13:02 -0500 |
| 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??? |
| Message-ID | <pfuaka$8v9$1@dont-email.me> |
| In reply to | #38371 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2018-06-14 14:09 -0400 |
| 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??? |
| Message-ID | <pfub0c$mf6$1@gioia.aioe.org> |
| In reply to | #38378 |
On 6/14/2018 2:02 PM, Knute Johnson wrote: > On 6/14/2018 01:14, siddareddy.moolam@gmail.com wrote: >> 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. isReachable is one of those methods that one should be very careful relying too much on. It can give both false negatives and false positives. The documentation sort of hint at it: <quote> Test whether that address is reachable. Best effort is made by the implementation to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host. </quote> It will do a "best effort". :-) Arne
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@mydomain.invalid> |
|---|---|
| Date | 2018-06-14 21:40 +0000 |
| 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??? |
| Message-ID | <pfund5$6b8$1@news.albasani.net> |
| In reply to | #38379 |
On Thu, 14 Jun 2018 14:09:18 -0400, Arne Vajhøj wrote: > On 6/14/2018 2:02 PM, Knute Johnson wrote: >> On 6/14/2018 01:14, siddareddy.moolam@gmail.com wrote: >>> 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. > > isReachable is one of those methods that one should be very careful > relying too much on. > > It can give both false negatives and false positives. > Indeed it does. On my LAN it says the openjdk version "1.8.0_171"machine its on is reachable but nothing else, internally or externally is. Yet ping can tag all the hosts I've tried it on. And, yes, InetAddress.getByName() successfully resolves these host names to the expected IP addresses. This is with Java openjdk version "1.8.0_171" on Fedora 27 fully patched as of last Friday. -- Martin | martin at Gregorie | gregorie dot org
[toc] | [prev] | [next] | [standalone]
| From | siddareddy.moolam@gmail.com |
|---|---|
| Date | 2018-06-13 23:16 -0700 |
| Subject | i need to check whether particular ip adress is up or down can anybody help me?? |
| Message-ID | <b6917017-795a-4307-a296-d7552ac56247@googlegroups.com> |
| In reply to | #38368 |
On Wednesday, 13 June 2018 16:09:45 UTC+5:30, siddared...@gmail.com wrote:
>
package com.techstar.com;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Server {
public static void runSystemCommand(String command) {
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String s = "";
// reading output stream of the command
while ((s = inputStream.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String ip = "192.168.15.71";
runSystemCommand("ping -c 1 " + ip);
}
}
output:
PING 192.168.15.71 (192.168.15.71) 56(84) bytes of data.
64 bytes from 192.168.15.71: icmp_seq=1 ttl=64 time=0.369 ms
--- 192.168.15.71 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.369/0.369/0.369/0.000 ms
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web