Ejemplo n.º 1
0
        private void UpdateItem(ListViewItem lvi)
        {
            DDnsDomain d = lvi.Tag as DDnsDomain;

            if (d == null)
            {
                return;
            }
            lvi.Name = lvi.Text = d.Domain;
            while (lvi.SubItems.Count < 2)
            {
                lvi.SubItems.Add("");
            }
            string rdesc = "";

            switch (d.ResolutionMode)
            {
            case DDnsResolutionMode.Server:
                rdesc = "by DuckDNS";
                break;

            case DDnsResolutionMode.Local:
                rdesc = "local";
                break;

            case DDnsResolutionMode.Fixed:
                rdesc = "fixed IP: " + d.ResolutionValue;
                break;

            case DDnsResolutionMode.Host:
                rdesc = "host " + d.ResolutionValue;
                break;

            case DDnsResolutionMode.WebService:
                rdesc = "url " + d.ResolutionValue;
                break;
            }
            lvi.SubItems[1].Text = rdesc;
        }
Ejemplo n.º 2
0
 public static void Execute(DDnsDomain d)
 {
     using (FEditDomain f = new FEditDomain(d))
         f.ShowDialog();
 }
Ejemplo n.º 3
0
        private void UpdateDomain(DDnsDomain d, List <string> messages)
        {
            try
            {
                string ipv4;
                string ipv6;
                switch (d.ResolutionMode)
                {
                case DDnsResolutionMode.Server:
                    ipv4 = "";
                    ipv6 = "";
                    break;

                case DDnsResolutionMode.Local:
                    getHostIPs(Dns.GetHostName(), out ipv4, out ipv6);
                    break;

                case DDnsResolutionMode.Fixed:
                    IPset(d.ResolutionValue, out ipv4, out ipv6);
                    break;

                case DDnsResolutionMode.Host:
                    getHostIPs(d.ResolutionValue, out ipv4, out ipv6);
                    break;

                case DDnsResolutionMode.WebService:
                    IPset(Cli().DownloadString(d.ResolutionValue), out ipv4, out ipv6);
                    break;

                default:
                    throw new Exception("Resolution mode not implemented");
                }
                if (ipv4 == null && ipv6 == null)
                {
                    messages.Add(d.Domain + ": IP resolution failed");
                    return;
                }
                string url = BuildURL(d.Domain, Token, ipv4, ipv6);// "https://www.duckdns.org/update?domains=" + d.Domain + "&token=" + Token + "&ip=" + ipv4 + "&ipv6=" + ipv6;
                string ret;
                if (!string.IsNullOrEmpty(d.BindIP))
                {
                    HttpWebRequest rq = (HttpWebRequest)WebRequest.Create(url);
                    rq.ServicePoint.BindIPEndPointDelegate = (sp, remoteEndPoint, retryCount) =>
                    {
                        return(new IPEndPoint(IPAddress.Parse(d.BindIP), 0));
                    };
                    rq.KeepAlive = false;
                    using (WebResponse response = rq.GetResponse())
                        using (Stream s = response.GetResponseStream())
                            using (StreamReader sr = new StreamReader(s, Encoding.ASCII))
                                ret = sr.ReadLine();
                }
                else
                {
                    ret = Cli().DownloadString(url);
                }
                if (ret != "OK")
                {
                    messages.Add(d.Domain + ": Failed");
                }
            }
            catch (Exception e)
            {
                messages.Add(d.Domain + ": " + e.GetType().Name + ": " + e.Message);
            }
        }