public void GetIpConfig_IoT()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(
                DevicePortal.IpConfigApi,
                this.PlatformType,
                this.FriendlyOperatingSystemVersion,
                HttpMethods.Get);

            Task <IpConfiguration> getTask = TestHelpers.Portal.GetIpConfigAsync();

            getTask.Wait();

            Assert.AreEqual(TaskStatus.RanToCompletion, getTask.Status);

            IpConfiguration ipconfig = getTask.Result;

            // Check some known things about this response.
            NetworkAdapterInfo adapter = ipconfig.Adapters[0];

            Assert.AreEqual("Bluetooth Device (Personal Area Network)", adapter.Description);
            Assert.AreEqual(4, adapter.Index);
            IpAddressInfo ipAddress = adapter.IpAddresses[0];

            Assert.AreEqual("0.0.0.0", ipAddress.Address);
            Assert.AreEqual("0.0.0.0", ipAddress.SubnetMask);
        }
        public void GetIpConfig_HoloLens_1607()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(
                DevicePortal.IpConfigApi,
                this.PlatformType,
                this.FriendlyOperatingSystemVersion,
                HttpMethods.Get);

            Task <IpConfiguration> getTask = TestHelpers.Portal.GetIpConfig();

            getTask.Wait();

            Assert.AreEqual(TaskStatus.RanToCompletion, getTask.Status);

            IpConfiguration ipconfig = getTask.Result;

            // Check some known things about this response.
            Assert.AreEqual(2, ipconfig.Adapters.Count);
            NetworkAdapterInfo adapter = ipconfig.Adapters[0];

            Assert.AreEqual("Bluetooth Device (Personal Area Network)", adapter.Description);
            Assert.AreEqual("4c-0b-be-ff-bd-64", adapter.MacAddress);
            Assert.AreEqual(7, adapter.Index);
            Assert.AreEqual(Guid.Parse("{765C05C8-7B46-4CE6-BEC9-33C6112234B4}"), adapter.Id);
            Assert.AreEqual("Ethernet", adapter.AdapterType);
            IpAddressInfo ipAddress = adapter.IpAddresses[0];

            Assert.AreEqual("0.0.0.0", ipAddress.Address);
            Assert.AreEqual("0.0.0.0", ipAddress.SubnetMask);
        }
Ejemplo n.º 3
0
 public NetworkAdapterInfo GetNetworkAdapterInfo()
 {
     using (IVirtualSystemSettingData systemSettingData = this._Vm.GetVirtualSystemSettingData())
     {
         using (IEthernetPortAllocationSettingData epasd = EthernetPortAllocationSettingData.GetRelated(systemSettingData).DisposingUnless <IEthernetPortAllocationSettingData>((Func <IEthernetPortAllocationSettingData, bool>)(e => e.Parent == ((IWMICommon)this._AdapterSettingData).Object.Path.Path)).FirstOrDefault <IEthernetPortAllocationSettingData>())
         {
             if (epasd == null)
             {
                 return new NetworkAdapterInfo()
                        {
                            SwitchPort = new SwitchPortInfo()
                            {
                                Name = string.Empty
                            },
                            VirtualSwitch = new VirtualSwitchInfo()
                            {
                                Label = string.Empty
                            }
                        }
             }
             ;
             string vsPath = epasd.HostResource == null || epasd.HostResource.Length == 0 ? string.Empty : epasd.HostResource[0];
             using (IEthernetSwitchPortVlanSettingData portVlanSettingData = EthernetSwitchPortVlanSettingData.GetRelated(epasd).FirstOrDefault <IEthernetSwitchPortVlanSettingData>())
             {
                 using (IEthernetSwitchPort ethernetSwitchPort = EthernetSwitchPort.GetRelated(epasd).FirstOrDefault <IEthernetSwitchPort>())
                 {
                     using (IVirtualEthernetSwitch virtualEthernetSwitch = VirtualEthernetSwitch.GetAllVirtualEthernetSwitches(this._Host).DisposingUnless <IVirtualEthernetSwitch>((Func <IVirtualEthernetSwitch, bool>)(v => ((IWMICommon)v).Object.Path.Path == vsPath)).FirstOrDefault <IVirtualEthernetSwitch>())
                     {
                         NetworkAdapterInfo networkAdapterInfo = new NetworkAdapterInfo()
                         {
                             SwitchPort    = new SwitchPortInfo(),
                             VirtualSwitch = new VirtualSwitchInfo()
                         };
                         if (ethernetSwitchPort == null)
                         {
                             if (virtualEthernetSwitch != null)
                             {
                                 networkAdapterInfo.SwitchPort.Name = virtualEthernetSwitch.ElementName;
                                 networkAdapterInfo.SwitchPort.Guid = virtualEthernetSwitch.Name;
                             }
                         }
                         else
                         {
                             networkAdapterInfo.SwitchPort.Name = ethernetSwitchPort.SystemName;
                             networkAdapterInfo.SwitchPort.Guid = ethernetSwitchPort.Name;
                         }
                         networkAdapterInfo.SwitchPort.AccessVLanId = portVlanSettingData == null ? 0 : (int)portVlanSettingData.AccessVlanId;
                         if (virtualEthernetSwitch != null)
                         {
                             networkAdapterInfo.VirtualSwitch.Label      = virtualEthernetSwitch.ElementName;
                             networkAdapterInfo.VirtualSwitch.SwitchUuid = virtualEthernetSwitch.Name;
                         }
                         return(networkAdapterInfo);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 private void OnNetworkConfigurationChanged(NetworkAdapterInfo originalConfiguration, NetworkAdapterInfo newConfiguration)
 {
     this.VerifyAndInitializeCallback();
     lock (DNSService.syncObject)
     {
         foreach (var callback in Runtime.Instance.Callbacks)
         {
             callback.OnNetworkConfigurationChanged(originalConfiguration, newConfiguration);
         }
     }
 }
Ejemplo n.º 5
0
 public NetworkAdapterInfo[] GetNetworkAdapters()
 {
     try
     {
         this.WriteEventLog("GetNetworkAdapters");
         this.VerifyAndInitializeCallback();
         return(NetworkAdapterInfo.GetAdapters());
     }
     catch (Exception ex)
     {
         this.WriteEventLog($"Error Exeucuting: {nameof(GetNetworkAdapters)}: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
         throw;
     }
 }
Ejemplo n.º 6
0
 void DNSService.IDNSServiceCallback.OnNetworkConfigurationChanged(NetworkAdapterInfo originalConfiguration, NetworkAdapterInfo newConfiguration)
 {
     Task.Run(() =>
     {
         this.Invoke(() =>
         {
             this.UpdateStatusMessage("Flushing DNS Cache...");
             FormMain.DnsFlushResolverCache();
             this.UpdateStatusMessage("Fetching DNS Configuration...");
             this.SelectedNetworkDevice.UpdateDNSConfiguration(newConfiguration.DNSConfiguration);
             this.UpdateDeviceDNSStatus(newConfiguration.DNSConfiguration);
             this.imgChangeDNS.Visible = !(this.SelectedDNSSetting.Equals(this.SelectedNetworkDevice.DNSConfiguration));
             this.UpdateStatusMessage();
         });
     });
 }
Ejemplo n.º 7
0
        private static int GetCount(NetworkAdapterInfo info, DiscoveryResult[] discoveryResult, out DiscoveryResult result)
        {
            List <DiscoveryResult> devices = GetRoutingDevices(discoveryResult);
            int index = 0;

            result = null;

            foreach (DiscoveryResult device in devices)
            {
                if (device.NetworkAdapterInfo.Equals(info))
                {
                    index++;
                    result = device;
                }
            }
            return(index);
        }
Ejemplo n.º 8
0
        public void ChangeDNS(DNSConfiguration newConfiguration, byte[] macAddress)
        {
            PhysicalAddress physicalAddress = new PhysicalAddress(macAddress);

            try
            {
                this.WriteEventLog($"{nameof(ChangeDNS)}({newConfiguration}, {macAddress})");
                this.VerifyAndInitializeCallback();
                NetworkAdapterInfo adapter = new NetworkAdapterInfo(physicalAddress);
                NetworkAdapterInfo originalConfiguration = adapter.Clone();
                uint responseCode = adapter.SetDNSConfiguration(newConfiguration);
                this.OnNetworkConfigurationChanged(adapter, new NetworkAdapterInfo(physicalAddress));
            }
            catch (Exception ex)
            {
                this.WriteEventLog($"Error Exeucuting: {nameof(ChangeDNS)}({newConfiguration}, {physicalAddress}): {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
            }
        }
Ejemplo n.º 9
0
        public DNSOperationResult GetDNSConfiguration(byte[] macAddress)
        {
            PhysicalAddress physicalAddress = new PhysicalAddress(macAddress);

            try
            {
                this.WriteEventLog($"{nameof(GetDNSConfiguration)}(${macAddress})");
                this.VerifyAndInitializeCallback();
                NetworkAdapterInfo networkAdapterInfo = new NetworkAdapterInfo(physicalAddress);
                var returnValue = new DNSOperationResult(networkAdapterInfo.GetDNSConfiguration());

                return(returnValue);
            }
            catch (Exception ex)
            {
                this.WriteEventLog($"Error Exeucuting: {nameof(GetDNSConfiguration)}({physicalAddress}): {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
                return(new DNSOperationResult(ex));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Intended to be called periodically, this method looks to see if
        /// network connection (IP address) has changed since the last time
        /// this method was called.
        /// </summary>
        /// <remarks>
        /// It would probalby be a better way of doing this if we used
        /// OpenNetCF's NetworkInterfaceWatcher class.
        /// </remarks>
        private void MonitorNetworkConnection()
        {
            try
            {
                NetworkAdapterInfo nic = Controller.GetWiredNetworkAdapter(); // will this ever return null? not sure.

                if (nic == null && _networkAdapterInfo == null)
                {
                    ReporterService.Networked = false;
                    return;
                }

                if (nic == null && _networkAdapterInfo != null ||
                    nic != null && _networkAdapterInfo == null)
                {
                    _networkAdapterInfo = nic;
                    LogNetworkAdapterInfo();
                    ReporterService.Networked = _networkAdapterInfo.IsNetworked();
                }
                else //  nic != null && nic != null
                {
                    // Only log something if we detect a network change.
                    if (nic.DhcpEnabled != _networkAdapterInfo.DhcpEnabled ||
                        nic.IpAddress != _networkAdapterInfo.IpAddress ||
                        nic.SubnetMask != _networkAdapterInfo.SubnetMask ||
                        nic.Gateway != _networkAdapterInfo.Gateway ||
                        nic.DnsPrimary != _networkAdapterInfo.DnsPrimary ||
                        nic.DnsSecondary != _networkAdapterInfo.DnsSecondary)
                    {
                        _networkAdapterInfo = nic;
                        LogNetworkAdapterInfo();
                        ReporterService.Networked = _networkAdapterInfo.IsNetworked();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Ejemplo n.º 11
0
        public override bool CollectReportData()
        {
            Boolean result = false;

            try
            {
                // productInfoItems.Clear();



                //List<String> test = InputConnectionInfo.DatabaseFields;

                foreach (ManagementObject mo in searcher.Get().AsParallel())
                {
                    NetworkAdapterInfo productInfo = new NetworkAdapterInfo()
                    {
                    };
                    foreach (String itemProp in InputConnectionInfo.WMIFields)
                    {
                        productInfo.GetType().GetProperty(itemProp).SetValue(productInfo, (WMIQueryBuilder.GetValue(mo, itemProp)), null);
                    }
                    productInfo.TimeStamp  = InputConnectionInfo.TimeStamp;
                    productInfo.SystemName = MachineDetails.ServerName;
                    UpdateStatus(productInfo.Name);
                    productInfoItems.Add(productInfo);
                    if (IsCancelRequested)
                    {
                        break;
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                AMTLogger.WriteToLog(ex.Message, MethodBase.GetCurrentMethod().Name, 0, AMTLogger.LogInfo.Error);
            }

            return(result);
        }
Ejemplo n.º 12
0
        public SystemInfo()
        {
            var osQuery = new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");
            var osSearcher = new ManagementObjectSearcher(osQuery);
            foreach (var os in osSearcher.Get())
            {
                memory.TotalPhysicalMemory = Convert.ToUInt64(os["TotalVisibleMemorySize"]) / 1024 / 1024;
                memory.AvailablePhysicalMemory = Convert.ToUInt64(os["FreePhysicalMemory"]) / 1024 / 1024;
                memory.TotalVirtualMemory = Convert.ToUInt64(os["TotalVirtualMemorySize"]) / 1024 / 1024;
                memory.AvailableVirtualMemory = Convert.ToUInt64(os["FreeVirtualMemory"]) / 1024 / 1024;
            }

            //处理器
            ManagementClass cimobjectProcessor = new ManagementClass("Win32_Processor");
            ManagementObjectCollection mocProcessor = cimobjectProcessor.GetInstances();
            foreach (ManagementObject mo in mocProcessor)
            {
                if (mo["ProcessorId"] != null) processor.SerialNumber = mo.Properties["ProcessorId"].Value.ToString().Trim();
                if (mo["Name"] != null) processor.Name = mo.Properties["Name"].Value.ToString().Trim();
                if (mo["Manufacturer"] != null) processor.Manufacturer = mo.Properties["Manufacturer"].Value.ToString().Trim();

            }

            //操作系统
            ManagementClass cimobjectOperatingSystem = new ManagementClass("Win32_OperatingSystem");
            ManagementObjectCollection mocOperatingSystem = cimobjectOperatingSystem.GetInstances();
            if (System.Environment.Is64BitOperatingSystem) operatingSystem.OSLevel = "64";
            foreach (ManagementObject mo in mocOperatingSystem)
            {
                if (mo["SerialNumber"] != null) operatingSystem.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim();
                if (mo["Caption"] != null) operatingSystem.Caption = mo.Properties["Caption"].Value.ToString().Trim();

                if (mo["InstallDate"] != null) operatingSystem.InstallDate = mo.Properties["InstallDate"].Value.ToString().Trim();
                if (mo["LastBootUpTime"] != null) operatingSystem.LastBootUpTime = mo.Properties["LastBootUpTime"].Value.ToString().Trim();
                if (mo["LocalDateTime"] != null) operatingSystem.LocalDateTime = mo.Properties["LocalDateTime"].Value.ToString().Trim();

            }
            //获取硬盘
            ManagementClass cimobjectDiskDrive = new ManagementClass("Win32_DiskDrive");
            ManagementObjectCollection mocDiskDrive = cimobjectDiskDrive.GetInstances();
            diskDrivelist = new List<DiskDriveInfo>();
            foreach (ManagementObject mo in mocDiskDrive)
            {
                DiskDriveInfo diskDrive = new DiskDriveInfo();
                if (mo["Caption"] != null) diskDrive.Name = mo.Properties["Caption"].Value.ToString().Trim();
                if (mo["SerialNumber"] != null) diskDrive.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim();
                if (mo["Size"] != null) diskDrive.Size = (ulong)mo.Properties["Size"].Value / 1024 / 1024 / 1024;
                if (!diskDrive.Name.StartsWith("USBKey")) diskDrivelist.Add(diskDrive);

            }
            //获取网卡地址
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection mocNetworkAdapter = mc.GetInstances();
            NetworkAdapterlist = new List<NetworkAdapterInfo>();
            foreach (ManagementObject mo in mocNetworkAdapter)
            {
                NetworkAdapterInfo networkAdapterInfo = new NetworkAdapterInfo();
                if (mo["Caption"] != null) networkAdapterInfo.Name = mo["Caption"].ToString().Trim();
                if (mo["MacAddress"] != null) networkAdapterInfo.MacAddress = mo["MacAddress"].ToString().Trim();
                if (!networkAdapterInfo.Name.Contains("VMware")
                    && !networkAdapterInfo.Name.Contains("Microsoft")
                    && !networkAdapterInfo.Name.Contains("Virtual")
                    && !networkAdapterInfo.Name.Contains("Miniport")
                    && networkAdapterInfo.MacAddress.Contains(":")
                    )
                {
                    NetworkAdapterlist.Add(networkAdapterInfo);
                }
            }
            //主板 
            ManagementClass cimobjectBaseBoard = new ManagementClass("WIN32_BaseBoard");
            ManagementObjectCollection mocBaseBoard = cimobjectBaseBoard.GetInstances();
            foreach (ManagementObject mo in mocBaseBoard)
            {
                if (mo["SerialNumber"] != null) baseBoard.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim();
                if (mo["Name"] != null) baseBoard.Name = mo.Properties["Name"].Value.ToString().Trim();
                if (mo["Manufacturer"] != null) baseBoard.Manufacturer = mo.Properties["Manufacturer"].Value.ToString().Trim();
                if (mo["Product"] != null) baseBoard.Product = mo.Properties["Product"].Value.ToString().Trim();
            }

            ManagementClass cimobjectBIOS = new ManagementClass("WIN32_BIOS");
            ManagementObjectCollection mocBIOS = cimobjectBIOS.GetInstances();

            foreach (ManagementObject mo in mocBIOS)
            {
                if (mo["SerialNumber"] != null) bios.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim();
                if (mo["Name"] != null) bios.Name = mo.Properties["Name"].Value.ToString().Trim();
                if (mo["Manufacturer"] != null) bios.Manufacturer = mo.Properties["Manufacturer"].Value.ToString().Trim();
                if (mo["ReleaseDate"] != null) bios.ReleaseDate = mo.Properties["ReleaseDate"].Value.ToString().Trim();
            }
        }