PHP: Why isn’t exec() returning output?
You should redirect stderr to stdout. To do that, change your exec() call like this: exec(“ping -c 1 $domain_bad 2>&1”, $output, $return_var); More info about 2>&1 meaning here.
You should redirect stderr to stdout. To do that, change your exec() call like this: exec(“ping -c 1 $domain_bad 2>&1”, $output, $return_var); More info about 2>&1 meaning here.
You can use the following code instead (I simply altered the write-host calls to CSV formatting) and execute it with “PowerShell.exe script.ps > output.csv” Note that you must execute it from the folder that contains hnames.txt, or simply change the “hnames.txt” to a full path. $names = Get-content “hnames.txt” foreach ($name in $names){ if (Test-Connection … Read more
Apple sample code: bytesSent = sendto( CFSocketGetNative(self->_socket), sock, [packet bytes], [packet length], 0, (struct sockaddr *) [self.hostAddress bytes], (socklen_t) [self.hostAddress length] ); to change the timeout: CFSocketNativeHandle sock = CFSocketGetNative(self->_socket); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 100000; // 0.1 sec setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, sizeof(tv)); bytesSent = sendto( sock, [packet bytes], [packet … Read more
Have a blast at The Ping Page, which has a link to full source on the original Unix ping(8).
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
Although ICMP uses RAW sockets (which require admin rights on Win2K and later), Microsoft circumvents its own security rules to allow its ICMP APIs to get through. As such, don’t use RAW sockets directly to send your own ICMP ping messages. Use IcmpSendEcho() and related functions instead.
Ping returns different exit codes depending on the type of error. ping 256.256.256.256 ; echo $? # 68 ping -c 1 127.0.0.1 ; echo $? # 0 ping -c 1 192.168.1.5 ; echo $? # 2 0 means host reachable 2 means unreachable
You can’t do this from JS. What you could do is this: client –AJAX– yourserver –ICMP ping– targetservers Make an AJAX request to your server, which will then ping the target servers for you, and return the result in the AJAX result. Possible caveats: this tells you whether the target servers are pingable from your … Read more
I have used following code to ping. public String ping(String url) { String str = “”; try { Process process = Runtime.getRuntime().exec( “/system/bin/ping -c 8 ” + url); BufferedReader reader = new BufferedReader(new InputStreamReader( process.getInputStream())); int i; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((i = reader.read(buffer)) > 0) output.append(buffer, 0, … Read more
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; }