How to ping in Java

To ping in Java you can use the following snippet.

Sample Java

public static void pingUrl(String url, Integer timeOut)
{
	url = url.replace("http://", "");
	try {  
		InetAddress address = InetAddress.getByName(url);  
		System.out.println("Hostname: " + address.getHostName());  
		System.out.println("IP-Address: " + address.getHostAddress());  
		System.out.println("Reachable in " + ((double)timeOut / (double)1000) + " Seconds: " + address.isReachable(timeOut));  
	}  
	catch (UnknownHostException e) {
		System.err.println("Unable to lookup " + url + "; error: " + e);  
	}  
	catch (IOException e) {  
		System.err.println("Unable to reach " + url);  
	}  
}

How to download a file in Powershell

To download a file in Powershell you can use the following snippet.

Sample Powershell

(New-Object System.Net.WebClient).DownloadFile('http://download.tuxfamily.org/notepadplus/6.6.6/npp.6.6.6.Installer.exe', 'C:\Users\MF\Codesnippets\Desktop\Download\npp.6.6.6.Installer.exe')