private string getExternalIP() { try { if (string.IsNullOrEmpty(urlForIPCheck)) { urlForIPCheck = "https://dynamix.run/ip.php"; } var response = GenericHelper.MakeHTTPGETRequest(urlForIPCheck); //Search for the ip in the html int first = response.IndexOf("Address: ") + 9; int last = response.LastIndexOf("</body>"); if (first != -1 && last != -1) { response = response.Substring(first, last - first); } response = GenericHelper.ParseIPv4Addr(response); //Write the IP to oldip.txt if (!string.IsNullOrEmpty(response) && GenericHelper.CheckIPValid(response)) { if (!File.Exists(oldIPFile)) { writeOldIP(response); oldIP = response; } else { oldIP = loadOldIP(); } currentIP.Text = response; } resetTimeLabels(); return(response); } catch { resetTimeLabels(); customError unableToConnect = new customError("Unable to determine your external IP address.", "Unable to contact " + urlForIPCheck + "\nA firewall has blocked the connection!\nYou have no connection to the internet!"); if (timer1.Enabled == true) { if (timer1.Interval > 10000) { unableToConnect.intervalForTimer = timer1.Interval; } else { unableToConnect.intervalForTimer = 10000; } } else { unableToConnect.intervalForTimer = 10000; } unableToConnect.Show(); //MessageBox.Show(" \n\tPossible causes:\n\t No internet connection\n\t DynDns IP service down.", "Error Determining IP", MessageBoxButtons.OK, MessageBoxIcon.Error); return(""); } }
private void updateIP() { if (oldIP != IPAddress && GenericHelper.CheckIPValid(IPAddress) && GenericHelper.CheckIPValid(oldIP)) { stopScanningInterval(); // Run configured external applications for when the IP address changes and pass in the parameters runExternalApps(); // Run IP updating services runInternetServices(); writeOldIP(IPAddress); oldIPLabel.Text = oldIP; oldIPLabel.Visible = true; oldIPLabelText.Visible = true; // Restart the scanning startScanning(); } }