Ping a list of host names and output the results to a csv in powershell

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

iOS – Ping with timeout

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

Ping Application in Android

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 ping in c#

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; }