Example #1
0
 public LocalIpViewModel(ILocalIp data)
 {
     _data        = data;
     _settingID   = data.SettingID;
     _macAddress  = data.MACAddress;
     _name        = data.Name;
     _dHCPEnabled = data.DHCPEnabled;
     if (!data.DHCPEnabled)
     {
         _isAutoDNSServer = false;
     }
     else
     {
         _isAutoDNSServer = string.IsNullOrEmpty(data.DNSServer0);
     }
     _isAutoDNSServerInitial = _isAutoDNSServer;
     _iPAddressVm            = new IpAddressViewModel(data.IPAddress);
     _iPSubnetVm             = new IpAddressViewModel(data.IPSubnet);
     _defaultIPGatewayVm     = new IpAddressViewModel(data.DefaultIPGateway);
     _dNSServer0Vm           = new IpAddressViewModel(data.DNSServer0);
     _dNSServer1Vm           = new IpAddressViewModel(data.DNSServer1);
     this.CopyIp             = new DelegateCommand(() => {
         string ip = _iPAddressVm.AddressText ?? "无";
         Clipboard.SetDataObject(ip, true);
         VirtualRoot.Out.ShowSuccess(ip, header: "复制成功");
     });
 }
Example #2
0
        public MainWindowViewModel()
        {
            this.Start = new DelegateCommand(() => {
                if (IsScanning)
                {
                    _thread?.Abort();
                    IsScanning = false;
                }
                else
                {
                    _thread?.Abort();
                    if (!IPAddress.TryParse(_fromIpAddressVm.AddressText, out _) || !IPAddress.TryParse(_toIpAddressVm.AddressText, out _))
                    {
                        throw new ValidationException("IP地址格式不正确");
                    }
                    if (Results.Count != 0)
                    {
                        Results.Clear();
                    }
                    List <string> ipList = Net.IpUtil.CreateIpRange(_fromIpAddressVm.AddressText, _toIpAddressVm.AddressText);
                    _thread = new Thread(new ThreadStart(() => {
                        Scan(ipList.ToArray());
                    }))
                    {
                        IsBackground = true
                    };
                    _thread.Start();
                }
            });
            var localIp = VirtualRoot.LocalIpSet.AsEnumerable().FirstOrDefault();

            if (localIp != null)
            {
                if (!string.IsNullOrEmpty(localIp.DefaultIPGateway))
                {
                    this._fromIpAddressVm = new IpAddressViewModel(Net.IpUtil.ConvertToIpString(Net.IpUtil.ConvertToIpNum(localIp.DefaultIPGateway) + 1));
                    string[] parts = localIp.DefaultIPGateway.Split('.');
                    parts[parts.Length - 1] = "255";
                    this._toIpAddressVm     = new IpAddressViewModel(string.Join(".", parts));
                }
            }
            _localIps = GetLocalIps();
        }
Example #3
0
 public LocalIpViewModel(ILocalIp data)
 {
     _data        = data;
     _settingID   = data.SettingID;
     _name        = data.Name;
     _dHCPEnabled = data.DHCPEnabled;
     if (!data.DHCPEnabled)
     {
         _isAutoDNSServer = false;
     }
     else
     {
         _isAutoDNSServer = string.IsNullOrEmpty(data.DNSServer0);
     }
     _isAutoDNSServerInitial = _isAutoDNSServer;
     _iPAddressVm            = new IpAddressViewModel(data.IPAddress);
     _iPSubnetVm             = new IpAddressViewModel(data.IPSubnet);
     _defaultIPGatewayVm     = new IpAddressViewModel(data.DefaultIPGateway);
     _dNSServer0Vm           = new IpAddressViewModel(data.DNSServer0);
     _dNSServer1Vm           = new IpAddressViewModel(data.DNSServer1);
 }