I am developing a PDA Application using c#,i need's to check internet connection before application starts execute,i have used the following code,which is working fine PDA system but not in Desktop
public static bool CheckForInternetConnection()
{
try
{
string hosname = System.Net.Dns.GetHostName();
IPHostEntry ent = Dns.GetHostEntry(hosname);
string ip = ent.AddressList[0].ToString();
bool ret = (ip != "127.0.0.1" && ip != "::1");
//MessageBox.Show(ret.ToString());
if (ret)
{
// MessageBox.Show("internet connected");
}
else
{
MessageBox.Show("internet not connected");
}
return ret;
}
catch
{
MessageBox.Show("internet not connected catch");
return false;
}
}
when I try to execute the same exe in desktop which is throwing me "internet not connected",where i am going wrong?
You have to ping google for example if a reply that means you have internet. What you've written is just checking if the device has ip address.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.