public class InternetCS { //Creating the extern function... [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int Description, int ReservedValue); //Creating a function that uses the API function... public static bool IsConnectedToInternet() { int Desc; return InternetGetConnectedState(out Desc, 0); } }
Bu da ping atan kod:
static void checkInternetConnExists() { try { Ping ping = new Ping(); string sHost = "www.zuppa.com"; string sResponse = ""; PingReply pingreply = ping.Send(sHost); sResponse += "Address: " + pingreply.Address + "\n"; sResponse += "Roundtrip Time: " + pingreply.RoundtripTime + "\n"; sResponse += "TTL (Time To Live): " + pingreply.Options.Ttl + "\n"; sResponse += "Buffer Size: " + pingreply.Buffer.Length.ToString() + "\n"; Console.WriteLine(sResponse); } catch (Exception err) { Console.WriteLine(err.Message); } }