Leave only two decimal places after the dot
string.Format is your friend. String.Format(“{0:0.00}”, 123.4567); // “123.46”
string.Format is your friend. String.Format(“{0:0.00}”, 123.4567); // “123.46”
I could not redirect the Perl based solution to a file for some reason so I kept searching and found a bash only way to do this: ping www.google.fr | while read pong; do echo “$(date): $pong”; done Wed Jun 26 13:09:23 CEST 2013: PING www.google.fr (173.194.40.56) 56(84) bytes of data. Wed Jun 26 13:09:23 … Read more
WindowsPowershell: option 1 ping.exe -t COMPUTERNAME|Foreach{“{0} – {1}” -f (Get-Date),$_} option 2 Test-Connection -Count 9999 -ComputerName COMPUTERNAME | Format-Table @{Name=”TimeStamp”;Expression={Get-Date}},Address,ProtocolAddress,ResponseTime
using System.Net.NetworkInformation; public static bool PingHost(string nameOrAddress) { bool pingable = false; Ping pinger = null; try { pinger = new Ping(); PingReply reply = pinger.Send(nameOrAddress); pingable = reply.Status == IPStatus.Success; } catch (PingException) { // Discard PingExceptions and return false; } finally { if (pinger != null) { pinger.Dispose(); } } return pingable; }
Without ping #!/bin/bash wget -q –spider http://google.com if [ $? -eq 0 ]; then echo “Online” else echo “Offline” fi -q : Silence mode –spider : don’t get, just check page availability $? : shell return code 0 : shell “All OK” code Without wget #!/bin/bash echo -e “GET http://google.com HTTP/1.0\n\n” | nc google.com 80 … Read more
Is this any good at all (will it do what I want?) You can do so. Another feasible way is using java.net.Socket. public static boolean pingHost(String host, int port, int timeout) { try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(host, port), timeout); return true; } catch (IOException e) { return false; // Either timeout … Read more
Destination Host Unreachable This message indicates one of two problems: either the local system has no route to the desired destination, or a remote router reports that it has no route to the destination. If the message is simply “Destination Host Unreachable,” then there is no route from the local system, and the packets to … Read more
If you don’t need to support Windows, here’s a really concise way to do it: import os hostname = “google.com” #example response = os.system(“ping -c 1 ” + hostname) #and then check the response… if response == 0: print hostname, ‘is up!’ else: print hostname, ‘is down!’ This works because ping returns a non-zero value … Read more
Assuming that it’s a TCP (rather than UDP) port that you’re trying to use: On the server itself, use netstat -an to check to see which ports are listening. From outside, just use telnet host port (or telnet host:port on Unix systems) to see if the connection is refused, accepted, or timeouts. On that latter … Read more
Docker images are pretty minimal, but you can install ping in your official ubuntu docker image via: apt-get update apt-get install iputils-ping Chances are you don’t need ping on your image, and just want to use it for testing purposes. Above example will help you out. But if you need ping to exist on your … Read more