EzDevInfo.com

ping interview questions

Top ping frequently asked interview questions

Pinging from a C/C++ program

I want to write a C or C++ program, that given an IP address, Pings it and then performs further action based on whether the Ping was successful or not. How to do this?


Source: (StackOverflow)

Fastest way to ping a network range and return responsive hosts?

Constraints:
1. Speed matters.
2. I am allowed to ping once.

I'm debating whether to use Python or shellscripting. Is there a method faster than bash?

Here is the current code,

for ip in $(seq int1 int2); do
    ping -c 1 xxx.xxx.xxx.$ip | grep "bytes from" &
done

Anything faster than this?


Source: (StackOverflow)

Advertisements

Using ping in c#

When I Ping a remote system with windows it says there is no reply, but when I ping with c# it says success. Windows is correct, the device is not connected. Why is my code able to successfully ping when Windows is not?

Here is my code :

Ping p1 = new Ping();
PingReply PR = p1.Send("192.168.2.18");
// check when the ping is not success
while (!PR.Status.ToString().Equals("Success"))
{
    Console.WriteLine(PR.Status.ToString());
    PR = p1.Send("192.168.2.18");
}
// check after the ping is n success
while (PR.Status.ToString().Equals("Success"))
{
    Console.WriteLine(PR.Status.ToString());
    PR = p1.Send("192.168.2.18");
}

Source: (StackOverflow)

Send a ping to each IP on a subnet

Is there a command line based way to send pings to each computer in a subnet? Like

for(int i = 1; i < 254; i++)
    ping(192.168.1.i);

to enforce arp resolution?


Source: (StackOverflow)

TraceRoute and Ping in C#

Does anyone have C# code handy for doing a ping and traceroute to a target computer? I am looking for a pure code solution, not what I'm doing now, which is invoking the ping.exe and tracert.exe program and parsing the output. I would like something more robust.


Source: (StackOverflow)

how to ping a server port with php?

i want a php code that give you the ping of and ip:port i have found a similar one but it only work for web site not on ip:port

<?php

function ping($host, $port, $timeout) 
{ 
  $tB = microtime(true); 
  $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); 
  if (!$fP) { return "down"; } 
  $tA = microtime(true); 
  return round((($tA - $tB) * 1000), 0)." ms"; 
}

//Echoing it will display the ping if the host is up, if not it'll say "down".
echo ping("www.google.com", 80, 10);

?>

++ i want this for game server this mean i type ip and port and i get the ping thats the idea of it


Source: (StackOverflow)

Checking host availability by using ping in bash scripts

I want to write a script, that would keep checking if any of the devices in network, that should be online all day long, are really online. I tried to use ping, but

if [ "`ping -c 1 some_ip_here`" ]
then
  echo 1
else
  echo 0
fi

gives 1 no matter if I enter valid or invalid ip address. How can I check if a specific address (or better any of devices from list of ip addresses) went offline?


Source: (StackOverflow)

How to determine if a port is open on a Windows server?

I'm trying to install a site under an alternative port on a server, but the port may be closed by a firewall. Is there a way to ping out or in, on a specific port, to see if it is open?


Source: (StackOverflow)

Ping a site in Python?

The basic code is:

from Tkinter import *
import os,sys

ana= Tk()
def ping1():
    os.system('ping')

a=Button(pen)
ip=("192.168.0.1")

a.config(text="PING",bg="white",fg="blue")
a=ping1.ip ??? 
a.pack()

ana.mainloop()

How could I ping a sites or address?


Source: (StackOverflow)

Pinging servers in Python

In Python, is there a way to ping a server through ICMP and return TRUE if the server responds, or FALSE if there is no response?


Source: (StackOverflow)

How to timestamp every ping result?

Ping returns this by default:

64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms

Is there some way I can get it to add the timestamp?

For example,

Mon 21 May 2012 15:15:37 EST | 64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms

I'm on OS X v10.7 (Lion) which seems to have some BSD version of ping.


Source: (StackOverflow)

How to ping ubuntu guest on VirtualBox [closed]

I have an VM (VirtualBox) with Ubuntu. Host machine is Windows 7. How can I ping my Ubuntu from host and vice versa? Trying to set "Bridged" connection type in VM settings but there is no effect, I only lose my internet connection in Ubuntu.


Source: (StackOverflow)

Preferred Java way to ping an HTTP URL for availability

I need a monitor class that regularly checks whether a given HTTP URL is available. I can take care of the "regularly" part using the Spring TaskExecutor abstraction, so that's not the topic here. The question is: What is the preferred way to ping a URL in java?

Here is my current code as a starting point:

try {
    final URLConnection connection = new URL(url).openConnection();
    connection.connect();
    LOG.info("Service " + url + " available, yeah!");
    available = true;
} catch (final MalformedURLException e) {
    throw new IllegalStateException("Bad URL: " + url, e);
} catch (final IOException e) {
    LOG.info("Service " + url + " unavailable, oh no!", e);
    available = false;
}
  1. Is this any good at all (will it do what I want)?
  2. Do I have to somehow close the connection?
  3. I suppose this is a GET request. Is there a way to send HEAD instead?

Source: (StackOverflow)

How can I write a linux bash script that tells me which computers are ON in my LAN?

How can I write a linux bash script that tells me which computers are ON in my LAN ?

It would help if I could give it as input a range of IP's.


Source: (StackOverflow)

ping response "Request timed out." vs "Destination Host unreachable"

When I ping an IP address, what is the difference between the responses "Request timed out." and "Destination Host unreachable" ?


Source: (StackOverflow)