示例#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);
        }
示例#3
0
 private void DrVoobly_Load(object sender, EventArgs e)
 {
     using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Voobly\Voobly", true))
     {
         if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Voobly\Voobly", "NATPort", null) != null)
         {
             string natport = key.GetValue("NATPort").ToString();
             VooblyNat       = natport;
             portlbl.Text    = VooblyNat + " (UDP)";
             portlbl.Enabled = true;
         }
         else
         {
             portlbl.Text = "Voobly Not Installed!";
         }
     }
     try
     {
         NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass();
         NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;
         foreach (NATUPNPLib.IStaticPortMapping portMapping in mappings)
         {
             if (portMapping.Description.ToString() == "Voobly-" + Environment.MachineName.ToString() && portMapping.InternalClient.ToString() == GetLocalIPAddress() && portMapping.InternalPort.ToString() == VooblyNat)
             {
                 fixport.Visible   = false;
                 checkport.Visible = true;
             }
         }
     }
     catch (SystemException)
     {
     }
 }
示例#4
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);
        }