コード例 #1
0
 public privateNetManager()
 {
     Peers = new Dictionary<string, NetworkPeerService>();
     dhcpManager = new DhcpServer();
     dhcpManager.ClearAcls();
     dhcpManager.AllowAny = true;
     dhcpManager.OnNewClient += new EventHandler<OnNewDHCPClientEvent>(dhcpManager_OnNewClient);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: prog76/SoftGetaway
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(String[] args)
        {
            DhcpServerConfigurationSection dhcpConfig = ConfigurationManager.GetSection("dhcpServer") as DhcpServerConfigurationSection;
            DhcpServer server = new DhcpServer();

            if (dhcpConfig != null)
            {
                if (dhcpConfig.NetworkInterface >= 0)
                {
                    server.DhcpInterface = NetworkInterface.GetAllNetworkInterfaces()[dhcpConfig.NetworkInterface];
                }

                server.StartAddress = InternetAddress.Parse(dhcpConfig.StartAddress.Trim());
                server.EndAddress = InternetAddress.Parse(dhcpConfig.EndAddress.Trim());
                server.Subnet = InternetAddress.Parse(dhcpConfig.Subnet.Trim());
                server.Gateway = InternetAddress.Parse(dhcpConfig.Gateway.Trim());
                server.LeaseDuration = dhcpConfig.LeaseDuration;
                server.OfferTimeout = dhcpConfig.OfferTimeout;
                server.DnsSuffix = dhcpConfig.DnsSuffix;

                foreach (InternetAddressElement dnsServer in dhcpConfig.DnsServers)
                {
                    server.DnsServers.Add(InternetAddress.Parse(dnsServer.IPAddress.Trim()));
                }

                foreach (PhysicalAddressElement macAllow in dhcpConfig.MacAllowList)
                {
                    if (macAllow.PhysicalAddress.Trim() == "*")
                    {
                        server.ClearAcls();
                        server.AllowAny = true;
                        break;
                    }
                    else
                    {
                        server.AddAcl(PhysicalAddress.Parse(macAllow.PhysicalAddress), false);
                    }
                }

                foreach (PhysicalAddressElement macDeny in dhcpConfig.MacDenyList)
                {
                    if (macDeny.PhysicalAddress.Trim() == "*")
                    {
                        server.ClearAcls();
                        server.AllowAny = false;
                        break;
                    }
                    else
                    {
                        server.AddAcl(PhysicalAddress.Parse(macDeny.PhysicalAddress), true);
                    }
                }

                foreach (PhysicalAddressMappingElement macReservation in dhcpConfig.MacReservationList)
                {
                    server.addReservation(macReservation.PhysicalAddress, macReservation.IPAddress);
                }
            }

            if (args.Length > 0 && (ContainsSwitch(args, "console") || ContainsSwitch(args, "debug")))
            {
                if (ContainsSwitch(args, "debug"))
                {
                    Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
                }

                DhcpHost host = new DhcpHost(server);
                host.ManualStart(args);

                Console.WriteLine("DHCP Service Running.");
                Console.WriteLine("Hit [Enter] to Terminate.");

                Console.ReadLine();

                host.ManualStop();
            }
            else
            {
                ServiceBase[] ServicesToRun;

                ServicesToRun = new ServiceBase[] { new DhcpHost(server) };

                ServiceBase.Run(ServicesToRun);
            }
        }
コード例 #3
0
ファイル: DhcpHost.cs プロジェクト: prog76/SoftGetaway
        public DhcpHost(DhcpServer server)
        {
            InitializeComponent();

            this.m_Server = server;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: prog76/SoftGetaway
        static void Main(string[] args)
        {
            DhcpServerConfigurationSection dhcpConfig = ConfigurationManager.GetSection("dhcpServer") as DhcpServerConfigurationSection;
            DhcpServer server = new DhcpServer();

            if (dhcpConfig != null)
            {
                if (dhcpConfig != null)
                {
                    if (dhcpConfig.NetworkInterface >= 0)
                    {
                        server.DhcpInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[dhcpConfig.NetworkInterface];
                    }

                    server.StartAddress = InternetAddress.Parse(dhcpConfig.StartAddress.Trim());
                    server.EndAddress = InternetAddress.Parse(dhcpConfig.EndAddress.Trim());
                    server.Subnet = InternetAddress.Parse(dhcpConfig.Subnet.Trim());
                    server.Gateway = InternetAddress.Parse(dhcpConfig.Gateway.Trim());
                    server.LeaseDuration = dhcpConfig.LeaseDuration;
                    server.OfferTimeout = dhcpConfig.OfferTimeout;
                    server.DnsSuffix = dhcpConfig.DnsSuffix;

                    server.StartAddress = InternetAddress.Parse("2.0.4.1");
                    server.EndAddress = InternetAddress.Parse("2.0.4.10");
                    server.Subnet = InternetAddress.Parse("255.255.255.0");

                    foreach (InternetAddressElement dnsServer in dhcpConfig.DnsServers)
                    {
                        server.DnsServers.Add(InternetAddress.Parse(dnsServer.IPAddress.Trim()));
                    }

                    foreach (PhysicalAddressElement macAllow in dhcpConfig.MacAllowList)
                    {
                        if (macAllow.PhysicalAddress.Trim() == "*")
                        {
                            server.ClearAcls();
                            server.AllowAny = true;
                            break;
                        }
                        else
                        {
                            server.AddAcl(PhysicalAddress.Parse(macAllow.PhysicalAddress), false);
                        }
                    }

                    foreach (PhysicalAddressElement macDeny in dhcpConfig.MacDenyList)
                    {
                        if (macDeny.PhysicalAddress.Trim() == "*")
                        {
                            server.ClearAcls();
                            server.AllowAny = false;
                            break;
                        }
                        else
                        {
                            server.AddAcl(PhysicalAddress.Parse(macDeny.PhysicalAddress), true);
                        }
                    }

                    foreach (PhysicalAddressMappingElement macReservation in dhcpConfig.MacReservationList)
                    {
                        server.addReservation(macReservation.PhysicalAddress, macReservation.IPAddress);
                    }
                }

                server.Start();
                Console.WriteLine("DHCP Service Running.");
                Console.WriteLine("Hit [Enter] to Terminate.");

                Console.ReadLine();

            }
        }