Ejemplo n.º 1
1
 public Router()
 {
     upnpnat = new NATUPNPLib.UPnPNAT();
     mappings = upnpnat.StaticPortMappingCollection;
 }
        public void ReloadUPNP()
        {
            Logger.Instance.eventLog.WriteEntry("Updating UPNP", EventLogEntryType.Information);
            RemoveUPNPMappings();

            if (int.Parse(Preferences.Instance.Value("upnpEnabled")) == 0)
            {
                return;
            }

            int    publicPort  = int.Parse(Preferences.Instance.Value("upnpPort"));
            int    privatePort = int.Parse(Preferences.Instance.Value("port"));
            string description = String.Format("iStatServerDotNet-{0}", Preferences.Instance.Value("upnpDescription"));

            NATUPNPLib.UPnPNAT upnpnat = new NATUPNPLib.UPnPNAT();
            NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;

            Logger.Instance.eventLog.WriteEntry("Fetching UPNP Addresses", EventLogEntryType.Information);
            var addresses = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList;

            foreach (var address in addresses)
            {
                string addressString = address.ToString();
                Match  match         = Regex.Match(addressString, @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    mappings.Add(publicPort, "TCP", privatePort, addressString, true, description);
                }
            }
            Logger.Instance.eventLog.WriteEntry("UPNP Complete", EventLogEntryType.Information);
        }
Ejemplo n.º 3
0
        private void button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView4.SelectedItems.Count; i++)
            {
                if (listView4.SelectedItems[i].Selected)
                {
                    try
                    {
                        try
                        {
                            NATUPNPLib.UPnPNAT UPnP = new NATUPNPLib.UPnPNAT();
                            NATUPNPLib.IStaticPortMappingCollection PortMapping = UPnP.StaticPortMappingCollection;
                            PortMapping.Remove(Convert.ToInt32(listView4.SelectedItems[i].SubItems[0].Text), "TCP");
                        }catch {}

                        if (_listener.Contains(_listener[i]))
                        {
                            _listener[i].Close();
                        }
                        else if (_FileListener.Contains(_FileListener[i]))
                        {
                            _FileListener[i].Close();
                        }

                        listView4.SelectedItems[i].Remove();
                    }catch {}
                }
            }
        }
        public void RemoveUPNPMappings()
        {
            Logger.Instance.eventLog.WriteEntry("Removing Exisiting UPNP Mappings", EventLogEntryType.Information);
            string description = String.Format("iStatServerDotNet-{0}", Preferences.Instance.Value("upnpDescription"));

            NATUPNPLib.UPnPNAT upnpnat = new NATUPNPLib.UPnPNAT();
            NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;
            foreach (NATUPNPLib.IStaticPortMapping portMapping in mappings)
            {
                if (portMapping.Description.Contains(description))
                {
                    mappings.Remove(portMapping.ExternalPort, "TCP");
                }
            }
            Logger.Instance.eventLog.WriteEntry("Finished Removing UPNP Mappings", EventLogEntryType.Information);
        }
 public void RemoveUPNPMappings()
 {
     Logger.Instance.eventLog.WriteEntry("Removing Exisiting UPNP Mappings", EventLogEntryType.Information);
     string description = String.Format("iStatServerDotNet-{0}", Preferences.Instance.Value("upnpDescription"));
     NATUPNPLib.UPnPNAT upnpnat = new NATUPNPLib.UPnPNAT();
     NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;
     foreach (NATUPNPLib.IStaticPortMapping portMapping in mappings)
     {
         if (portMapping.Description.Contains(description))
         {
             mappings.Remove(portMapping.ExternalPort, "TCP");
         }
     }
     Logger.Instance.eventLog.WriteEntry("Finished Removing UPNP Mappings", EventLogEntryType.Information);
 }
Ejemplo n.º 6
-1
        private void button4_Click(object sender, EventArgs e)
        {
            for(int i = 0; i < listView4.SelectedItems.Count; i++)
            {
                if(listView4.SelectedItems[i].Selected)
                {
                    try
                    {
                        try
                        {
                            NATUPNPLib.UPnPNAT UPnP = new NATUPNPLib.UPnPNAT();
                            NATUPNPLib.IStaticPortMappingCollection PortMapping = UPnP.StaticPortMappingCollection;
                            PortMapping.Remove(Convert.ToInt32(listView4.SelectedItems[i].SubItems[0].Text), "TCP");
                        }catch{}

                        if(_listener.Contains(_listener[i]))
                            _listener[i].Close();
                        else if(_FileListener.Contains(_FileListener[i]))
                            _FileListener[i].Close();

                        listView4.SelectedItems[i].Remove();
                    }catch{}

                }
            }
        }
        public void ReloadUPNP()
        {
            Logger.Instance.eventLog.WriteEntry("Updating UPNP", EventLogEntryType.Information);
            RemoveUPNPMappings();

            if (int.Parse(Preferences.Instance.Value("upnpEnabled")) == 0)
                return;

            int publicPort = int.Parse(Preferences.Instance.Value("upnpPort"));
            int privatePort = int.Parse(Preferences.Instance.Value("port"));
            string description = String.Format("iStatServerDotNet-{0}", Preferences.Instance.Value("upnpDescription"));

            NATUPNPLib.UPnPNAT upnpnat = new NATUPNPLib.UPnPNAT();
            NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;

            Logger.Instance.eventLog.WriteEntry("Fetching UPNP Addresses", EventLogEntryType.Information);
            var addresses = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList;
            foreach (var address in addresses)
            {
                string addressString = address.ToString();
                Match match = Regex.Match(addressString, @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    mappings.Add(publicPort, "TCP", privatePort, addressString, true, description);
                }
            }
            Logger.Instance.eventLog.WriteEntry("UPNP Complete", EventLogEntryType.Information);
        }