// This service creates a Dns server public static void Main() { // Initialize logging Logger.Initialize(new DebugLogger(), LoggerLevel.Debug); // Create the Dns server DnsService DnsServer = new DnsService(); // Set the device server name and Dns suffix offered to client DnsServer.ServerName = "example"; DnsServer.DnsSuffix = "iot.local"; // Sets interface ip address DnsServer.InterfaceAddress = IPAddress.GetDefaultLocalAddress(); // Add a resource record to the zone table Answer record = new Answer(); record.Domain = string.Concat(DnsServer.ServerName, ".", DnsServer.DnsSuffix); record.Class = RecordClass.IN; record.Type = RecordType.A; record.Ttl = 60; record.Record = new ARecord(DnsServer.InterfaceAddress.ToString()); DnsServer.ZoneFile.Add(record); // Enable Dns server to relay requests that can not be looked up locally to another Dns server. DnsServer.PrimaryServer = "8.8.8.8"; DnsServer.IsProxy = true; // Starts Dns service DnsServer.Start(); }
public void StartAll() { _service = this; // DHCP Service if (_dhcpEnabled == true) { _dhcpService.InterfaceAddress = _interfaceAddress; _dhcpService.ServerName = _serverName; _dhcpService.DnsSuffix = _dnsSuffix; _dhcpService.StorageRoot = _storageRoot; if (_sntpEnabled == true) { _dhcpService.RemoveOption(DhcpOption.NTPServer); _dhcpService.AddOption(DhcpOption.NTPServer, _interfaceAddress.GetAddressBytes()); } _dhcpService.Start(); } // DNS Service if (_dnsEnabled == true) { _dnsService.InterfaceAddress = _interfaceAddress; _dnsService.ServerName = _serverName; _dnsService.DnsSuffix = _dnsSuffix; if (!StringUtility.IsNullOrEmpty(_serverName) || !StringUtility.IsNullOrEmpty(_dnsSuffix)) { Answer record = new Answer(); record.Domain = string.Concat(_serverName, ".", _dnsSuffix); record.Class = RecordClass.IN; record.Type = RecordType.A; record.Ttl = 60; record.Record = new ARecord(_interfaceAddress.GetAddressBytes()); _service.DnsService.ZoneFile.Add(record); Logger.WriteInfo(this, "Device registered with dns: " + record.Domain); } _dnsService.Start(); } // SNTP Service if (_sntpEnabled == true) { _sntpService.InterfaceAddress = _interfaceAddress; _sntpService.Start(); } // HTTP Service if (_httpEnabled == true) { ModuleManager _moduleManager = new ModuleManager(); // Add the router module as the fist module to pipeline _moduleManager.Add(new RouterModule()); if (StorageRoot != null) { // Create disk file service for the root storage DiskFileService fileService = new DiskFileService("/", StorageRoot + @"\"+ MicroServer.Net.Http.Constants.HTTP_WEB_ROOT_FOLDER + @"\"); // Add the file module to pipeline _moduleManager.Add(new FileModule(fileService) { AllowListing = _allowListing }); } // Add the controller module to pipeline _moduleManager.Add(new ControllerModule()); // Add the error module as the last module to pipeline _moduleManager.Add(new ErrorModule()); // Create the Http service _httpService = new HttpService(_moduleManager); _httpService.InterfaceAddress = _interfaceAddress; _httpService.Start(); } Logger.WriteInfo(this, "Service Manager started all services"); }