コード例 #1
0
ファイル: AddPointForm.cs プロジェクト: rickparrish/PDDNS
        void cmdRetrieve_Click(object sender, EventArgs e)
        {
            if (!Dialog.ValidateIsEmailAddress(txtEmailAddress)) return;
            if (!Dialog.ValidateIsNotEmpty(txtAPIKey)) return;

            lvZoneRecords.Items.Clear();

            using (RMWebClient WC = new RMWebClient())
            {
                WC.ContentType = "application/xml";
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(txtEmailAddress.Text.Trim() + ":" + txtAPIKey.Text.Trim()));
                WC.Headers["Accept"] = "application/xml";
                WC.UseDefaultCredentials = false;

                // Get all zones
                try
                {
                    string ZonesXml = WC.DownloadString("https://pointhq.com/zones");
                    XmlSerializer XS = new XmlSerializer(typeof(Point.zones));
                    Point.zones Zones = null;
                    using (TextReader TR = new StringReader(ZonesXml))
                    {
                        Zones = (Point.zones)XS.Deserialize(TR);
                    }

                    // Now get all records for each zone
                    foreach (Point.zonesZone Zone in Zones.zone)
                    {
                        string ZoneRecordsXml = WC.DownloadString("https://pointhq.com/zones/" + Zone.id.ToString() + "/records");
                        XS = new XmlSerializer(typeof(Point.zonerecords));
                        Point.zonerecords ZoneRecords = null;
                        using (TextReader TR = new StringReader(ZoneRecordsXml))
                        {
                            ZoneRecords = (Point.zonerecords)XS.Deserialize(TR);
                        }

                        foreach (Point.zonerecordsZonerecord ZoneRecord in ZoneRecords.zonerecord)
                        {
                            if (ZoneRecord.recordtype.ToUpper() == "A")
                            {
                                ListViewItem LVI = new ListViewItem(ZoneRecord.name.TrimEnd('.'));
                                LVI.SubItems.Add(ZoneRecord.zoneid.ToString());
                                LVI.SubItems.Add(ZoneRecord.id.ToString());
                                lvZoneRecords.Items.Add(LVI);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.instance.LogException("Error retrieving Point zone records", ex);
                    Dialog.Error("Error retrieving hostnames:\r\n\r\n" + ex.Message, "Error");
                }
            }
        }
コード例 #2
0
ファイル: UPnP.cs プロジェクト: Samotron/RMLib
        private static string GetServiceUrl(string descriptionUrl)
        {
            // Download description file from router
            string ResponseText = "";

            using (RMWebClient WC = new RMWebClient())
            {
                WC.Timeout   = 5000;
                ResponseText = WC.DownloadString(descriptionUrl);
            }

            // Load xml into parser
            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.LoadXml(ResponseText);

            // Add namespace
            XmlNamespaceManager NSManager = new XmlNamespaceManager(XmlDoc.NameTable);

            NSManager.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");

            // Find deviceType node and ensure it's an internet gateway device
            XmlNode DeviceTypeNode = XmlDoc.SelectSingleNode("//tns:device/tns:deviceType/text()", NSManager);

            if (!DeviceTypeNode.Value.ToLower().Contains("internetgatewaydevice"))
            {
                return(null);
            }

            // Find controlURL node
            XmlNode ControlUrlNode = XmlDoc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:WANIPConnection:1\"]/tns:controlURL/text()", NSManager);

            if (ControlUrlNode == null)
            {
                _WANPPP        = true;
                ControlUrlNode = XmlDoc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:WANPPPConnection:1\"]/tns:controlURL/text()", NSManager);
                if (ControlUrlNode == null)
                {
                    return(null);
                }
            }

            // Return the path to the service url
            string BaseUrl = descriptionUrl.Substring(7);         // Trim http://

            BaseUrl = BaseUrl.Substring(0, BaseUrl.IndexOf("/")); // Trim everything after first /
            if (ControlUrlNode.Value.StartsWith("/"))
            {
                return("http://" + BaseUrl + ControlUrlNode.Value);
            }
            else
            {
                return("http://" + BaseUrl + "/" + ControlUrlNode.Value);
            }
        }
コード例 #3
0
ファイル: WebUtils.cs プロジェクト: Robin--/RMLib
 static public string HttpGet(string url)
 {
     try
     {
         using (RMWebClient WC = new RMWebClient())
         {
             return(WC.DownloadString(url));
         }
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
コード例 #4
0
ファイル: WebUtils.cs プロジェクト: Robin--/RMLib
        public static IPAddress GetExternalIPv4ByHttp(int port)
        {
            using (RMWebClient WC = new RMWebClient())
            {
                WC.Timeout = 5000;
                string IP = WC.DownloadString("http://www.randm.ca:" + port.ToString() + "/whats-my-ip.php");

                // Return if it's valid
                IPAddress Result = IPAddress.None;
                if (IPAddress.TryParse(IP, out Result) && !WebUtils.IsPrivateIP(Result))
                {
                    return(Result);
                }
            }

            return(IPAddress.None);
        }
コード例 #5
0
ファイル: NoIPProvider.cs プロジェクト: rickparrish/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(HC.Username + ":" + HC.Password.GetPlainText()));
                WC.UseDefaultCredentials = false;
                WC.UserAgent = ProcessUtils.CompanyName + " " + ProcessUtils.ProductName + "/" + ProcessUtils.ProductVersion + " [email protected]";

                string Url = "https://dynupdate.no-ip.com/nic/update";
                Url += "?hostname=" + Uri.EscapeDataString(HC.Hostname);
                Url += "&myip=" + ipAddress.ToString();

                string ResponseText = WC.DownloadString(Url).Trim().ToLower();
                if (ResponseText.Contains(ipAddress.ToString()))
                {
                    if (ResponseText.Contains("nochg"))
                    {
                        Logging.instance.LogWarning("Host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + ") successfully updated, but returned NOCHG response.  Too many of these could cause your account to be banned by the provider.");
                    }
                }
                else
                {
                    HC.Disabled = true;
                    switch (ResponseText)
                    {
                        case "nohost": HC.DisabledReason = "Hostname supplied does not exist under specified account"; break;
                        case "badauth": HC.DisabledReason = "Invalid username password combination"; break;
                        case "badagent": HC.DisabledReason = "Client disabled."; break;
                        case "!donator": HC.DisabledReason = "An update request was sent including a feature that is not available to that particular user such as offline options."; break;
                        case "abuse": HC.DisabledReason = "Username is blocked due to abuse. Either for not following our update specifications or disabled due to violation of the No-IP terms of service."; break;
                        case "911":
                            Logging.instance.LogWarning("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): A fatal error on the provider's side such as a database outage.  Will retry in 1 hour.");
                            return;
                        default: HC.DisabledReason = "An unknown response code was received: \"" + ResponseText + "\""; break;
                    }
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
            }
        }
コード例 #6
0
ファイル: DtDNSProvider.cs プロジェクト: rickparrish/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                string Url = "https://www.dtdns.com/api/autodns.cfm";
                Url += "?id=" + Uri.EscapeDataString(HC.Hostname);
                Url += "&pw=" + Uri.EscapeDataString(HC.Password.GetPlainText());
                Url += "&ip=" + ipAddress.ToString();
                Url += "&client=PDDNS";

                string ResponseText = WC.DownloadString(Url).Trim();
                if (!ResponseText.Contains(ipAddress.ToString()))
                {
                    HC.Disabled = true;
                    HC.DisabledReason = ResponseText;
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
            }
        }
コード例 #7
0
ファイル: UPnP.cs プロジェクト: Robin--/RMLib
        private static string GetServiceUrl(string descriptionUrl)
        {
            // Download description file from router
            string ResponseText = "";
            using (RMWebClient WC = new RMWebClient())
            {
                WC.Timeout = 5000;
                ResponseText = WC.DownloadString(descriptionUrl);
            }

            // Load xml into parser
            XmlDocument XmlDoc = new XmlDocument();
            XmlDoc.LoadXml(ResponseText);

            // Add namespace
            XmlNamespaceManager NSManager = new XmlNamespaceManager(XmlDoc.NameTable);
            NSManager.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");

            // Find deviceType node and ensure it's an internet gateway device
            XmlNode DeviceTypeNode = XmlDoc.SelectSingleNode("//tns:device/tns:deviceType/text()", NSManager);
            if (!DeviceTypeNode.Value.ToLower().Contains("internetgatewaydevice")) return null;

            // Find controlURL node
            XmlNode ControlUrlNode = XmlDoc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:WANIPConnection:1\"]/tns:controlURL/text()", NSManager);
            if (ControlUrlNode == null)
            {
                _WANPPP = true;
                ControlUrlNode = XmlDoc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:WANPPPConnection:1\"]/tns:controlURL/text()", NSManager);
                if (ControlUrlNode == null) return null;
            }

            // Return the path to the service url
            string BaseUrl = descriptionUrl.Substring(7); // Trim http://
            BaseUrl = BaseUrl.Substring(0, BaseUrl.IndexOf("/")); // Trim everything after first /
            if (ControlUrlNode.Value.StartsWith("/"))
            {
                return "http://" + BaseUrl + ControlUrlNode.Value;
            }
            else
            {
                return "http://" + BaseUrl + "/" + ControlUrlNode.Value;
            }
        }
コード例 #8
0
ファイル: WebUtils.cs プロジェクト: Robin--/RMLib
 public static string HttpGet(string url)
 {
     try
     {
         using (RMWebClient WC = new RMWebClient())
         {
             return WC.DownloadString(url);
         }
     }
     catch (Exception)
     {
         return string.Empty;
     }
 }
コード例 #9
0
ファイル: WebUtils.cs プロジェクト: Robin--/RMLib
        public static IPAddress GetExternalIPv4ByHttp(int port)
        {
            using (RMWebClient WC = new RMWebClient())
            {
                WC.Timeout = 5000;
                string IP = WC.DownloadString("http://www.randm.ca:" + port.ToString() + "/whats-my-ip.php");

                // Return if it's valid
                IPAddress Result = IPAddress.None;
                if (IPAddress.TryParse(IP, out Result) && !WebUtils.IsPrivateIP(Result)) return Result;
            }

            return IPAddress.None;
        }