Hello,
I am trying to find all possible operative system/router/adapter reasons what can cause internet to stop connecting.
The goal is to create code that check for all those reasons and programatically resolves those issues.
I have found 2 codes that do reconnect the internet connection if not connected.
Example 1: enables the network adapter if disabled using "\" enable"
Example 2: I don't know what this code is doing. What is that code doing and how is it possible to check for if we need to "/renew" the connection?
Using "/renew" and "/release" connects and disconnects to internet in Example 2
//Example 1: Checking the network adapter
private void button2_Click(object sender, EventArgs e)
{
bool isconnected = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
if (isconnected == false)
{
EnableNetWorkAdapter("Local Area Connection");
}
}
static void EnableNetWorkAdapter(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" enable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
//Example 2: What is actually renewed here and how to check if we need to "/renew" the connection?
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "ipconfig";
info.Arguments = "/renew"; // or renew/release if you want to connect/disconnect
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit();