Exemplo n.º 1
0
		private void WlanScanCompleted(Nic sender)
		{
			Application.Current.Dispatcher.BeginInvoke(new Action(ApplyScan));

			if (State.IsAutoScanActive && !Result.TargetNic.Wlan.State.IsScanning)
				Result.TargetNic.Wlan.Scan();
		}
Exemplo n.º 2
0
		public void Initialize(Nic targetNic, IPAddress from = null, IPAddress to = null)
		{
			if (from == null)
				from = targetNic.Ip.V4.PrimaryUnicast.Network.FirstAddress;
			if (to == null)
				to = targetNic.Ip.V4.PrimaryUnicast.Network.LastAddress;

			uint firstUint = BitConverter.ToUInt32(from.GetAddressBytes().Reverse().ToArray(), 0);
			uint lastUint = BitConverter.ToUInt32(to.GetAddressBytes().Reverse().ToArray(), 0);

			//for (uint i = firstUint; i <= lastUint; i++)
			for (uint i = firstUint; i <= lastUint; i++)
			{
				var ipAddress = new IPAddress(BitConverter.GetBytes(i).Reverse().ToArray());
				var hostScan = new HostScan(ipAddress, targetNic.Ip.V4.PrimaryUnicast.Address);

				hostScan.Options = Options.HostScanOptions;
				hostScan.Options.Dns.DnsServer = targetNic.Raw.IpProperties.DnsAddresses.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);

				hostScan.State.Online += HostOnline;
				hostScan.State.Completed += HostScanCompleted;
				_scans.Add(hostScan);
			}

			Results.SetTotalScans((ushort) Scans.Count);
			Results.SetLocalNic(targetNic);
		}
Exemplo n.º 3
0
		public void Initialize(Nic targetNic, IPAddress from = null, IPAddress to = null)
		{
			if (from == null)
				from = targetNic.Ip.V4.PrimaryUnicast.Network.FirstAddress;
			if (to == null)
				to = targetNic.Ip.V4.PrimaryUnicast.Network.LastAddress;

			uint firstUint = BitConverter.ToUInt32(from.GetAddressBytes().Reverse().ToArray(), 0);
			uint lastUint = BitConverter.ToUInt32(to.GetAddressBytes().Reverse().ToArray(), 0);

			//for (uint i = firstUint; i <= lastUint; i++)
			for (uint i = firstUint; i <= lastUint; i++)
			{
				var ipAddress = new IPAddress(BitConverter.GetBytes(i).Reverse().ToArray());
				var observer = new HostObserver(ipAddress, targetNic.Ip.V4.PrimaryUnicast.Address);

				observer.Options = Options.HostObserver;
				//hostChangeDetector.Options.Dns.DnsServer = targetNic.Raw.IpProperties.DnsAddresses.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);

				observer.State.ObserverSucceeded += ObserverSucceeded;
				observer.State.Activated += ObserverActivated;
				observer.State.Deactivated += ObserverDeactivated;

				_detectors.Add(observer);
			}

			Results.SetLocalNic(targetNic);
		}
Exemplo n.º 4
0
			public static Task<NbnsRecordNB.AddressEntryRecord[]> Addresses(string hostname, Nic localAddress, int attempts = 2, int timeout = 1000)
			{
				if (localAddress == null || localAddress.Ip.V4.IsSupported == false || localAddress.Ip.V4.PrimaryUnicast == null)
					throw new Exception("invalid local address");

				var localUnicast = localAddress.Ip.V4.PrimaryUnicast;

				var request = new NbnsPacket();
				request.Header.RecursionDesired = true;
				request.Header.Broadcast = true;
				request.Questions = new[] {new NbnsQuestion {Type = NbnsCodes.QTypes.Nb, Name = hostname.ToUpper()}};
				return request.SendAsync(localUnicast.Network.BroadcastAddress, 137, localUnicast.Address, attempts, timeout)
							.ContinueWith(t =>
							{
								if (t.Exception != null)
									throw t.Exception.InnerException;

								NbnsPacket response = t.Result;
								if (response.Header.ResultCode != NbnsCodes.RCodes.NoError)
									throw new CfnException(response.Header.ResultCode.GetThrowMessage());
								return ((NbnsRecordNB) (response.Answers.First().Record)).AddressEntries;
							});
			}
Exemplo n.º 5
0
		/// <summary>Retrieves the basic service sets (BSS) list of all available networks.</summary>
		internal static WlanInternBssEntry[] TryGetBssList(Nic nic)
		{
			int error;
			return GetBssList(nic, out error);
		}
Exemplo n.º 6
0
		/// <summary>Retrieves the list of available networks.</summary>
		internal static WlanInternSsidEntry[] TryGetSsidList(Nic nic)
		{
			int error;
			var result = GetSsidList(nic, out error);
			return result;
		}
Exemplo n.º 7
0
		/// <summary>Sets a parameter of the interface whose data type is <see cref="int" />.</summary>
		internal static void TrySetOpCode(Nic nic, WlanInternOpcode opCode, int value)
		{
			int error;
			SetOpCode(nic, opCode, value, out error);
		}
Exemplo n.º 8
0
				public static Task<RecordAAAA[]> GetAsnyc(string hostname, IPAddress dnsServer, Nic localNic, int attempts = 2, int timeout = 1000)
				{
					var t = new Task<RecordAAAA[]>(() => Get(hostname, dnsServer, localNic, attempts, timeout), TaskCreationOptions.LongRunning);
					t.Start(TaskScheduler.Default);
					return t;
				}
Exemplo n.º 9
0
		public void SetTargetNic(Nic targetNic)
		{
			TargetNic = targetNic;
		}
Exemplo n.º 10
0
		private static int GetOpCode(Nic nic, WlanInternOpcode opCode, out int errorCode)
		{
			IntPtr valuePtr;
			int valueSize;
			WlanInternOpcodeValueType opcodeValueType;
			if ((errorCode = WlanInterop.QueryInterface(_handle, nic.Hardware.Id, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType)) != 0)
				return 0;
			try
			{
				return Marshal.ReadInt32(valuePtr);
			}
			finally
			{
				WlanInterop.FreeMemory(valuePtr);
			}
		}
Exemplo n.º 11
0
		/// <summary>Sets a parameter of the interface whose data type is <see cref="int" />.</summary>
		internal static void SetOpCode(Nic nic, WlanInternOpcode opCode, int value)
		{
			int error;
			SetOpCode(nic, opCode, value, out error);
			ThrowIfError(error);
		}
Exemplo n.º 12
0
		internal void SetLocalNic(Nic localNic)
		{
			LocalNic = localNic;
			NetworkId = localNic.Ip.V4.PrimaryUnicast.Network.Id;
			DnsSuffix = localNic.Ip.DnsSuffix;
		}
Exemplo n.º 13
0
		public static void Reload()
		{
			var interfaces = NetworkInterface.GetAllNetworkInterfaces();
			var existing = _all.ToList();

			foreach (var newI in interfaces)
			{
				var exisI = existing.FirstOrDefault(x => x.Hardware.Id == Guid.Parse(newI.Id));
				if (exisI != null)
				{
					existing.Remove(exisI);
					exisI.Reload(newI);
				}
				else
				{
					var item = new Nic(newI);
					_all.Add(item);
					NicsPerId.Add(item.Hardware.Id, item);
				}
			}

			foreach (var nic in existing)
			{
				_all.Remove(nic);
				NicsPerId.Remove(nic.Hardware.Id);
			}

			for (int future = 0; future < interfaces.Length; future++)
			{
				for (int actuall = 0; actuall < _all.Count; actuall++)
				{
					if (_all[actuall].Hardware.Id.Equals(Guid.Parse(interfaces[future].Id)))
					{
						if (actuall != future)
							_all.Move(actuall, future);
						break;
					}
				}
			}
		}
Exemplo n.º 14
0
		private void ConnectivityCheckRequired(Nic sender)
		{
			if (_isInitializing)
				return;
			WwwConnectivity.CheckAsync();
		}
Exemplo n.º 15
0
		private static WlanInternBssEntry[] GetBssList(Nic nic, out int errorCode)
		{
			IntPtr bssListPtr;
			if ((errorCode = WlanInterop.GetBssEntryList(_handle, nic.Hardware.Id, IntPtr.Zero, BssType.Any, false, IntPtr.Zero, out bssListPtr)) != 0)
				return new WlanInternBssEntry[0];
			try
			{
				var bssListHeader = (WlanInternBssEntryListHeader) Marshal.PtrToStructure(bssListPtr, typeof (WlanInternBssEntryListHeader));
				long bssListIt = bssListPtr.ToInt64() + Marshal.SizeOf(typeof (WlanInternBssEntryListHeader));
				var bssEntries = new WlanInternBssEntry[bssListHeader.numberOfItems];
				for (int i = 0; i < bssListHeader.numberOfItems; ++i)
				{
					bssEntries[i] = (WlanInternBssEntry) Marshal.PtrToStructure(new IntPtr(bssListIt), typeof (WlanInternBssEntry));
					bssListIt += Marshal.SizeOf(typeof (WlanInternBssEntry));
				}
				errorCode = 0;
				return bssEntries;
			}
			finally
			{
				WlanInterop.FreeMemory(bssListPtr);
			}
		}
Exemplo n.º 16
0
		private static WlanInternSsidEntry[] GetSsidList(Nic nic, out int errorCode)
		{
			IntPtr availNetListPtr;
			if ((errorCode = WlanInterop.GetSsidEntryList(_handle, nic.Hardware.Id, 0, IntPtr.Zero, out availNetListPtr)) != 0)
				return new WlanInternSsidEntry[0];
			try
			{
				var availNetListHeader = (WlanInternSsidEntryListHeader) Marshal.PtrToStructure(availNetListPtr, typeof (WlanInternSsidEntryListHeader));
				long availNetListIt = availNetListPtr.ToInt64() + Marshal.SizeOf(typeof (WlanInternSsidEntryListHeader));
				var ssidEntries = new WlanInternSsidEntry[availNetListHeader.numberOfItems];
				for (int i = 0; i < availNetListHeader.numberOfItems; ++i)
				{
					ssidEntries[i] = (WlanInternSsidEntry) Marshal.PtrToStructure(new IntPtr(availNetListIt), typeof (WlanInternSsidEntry));
					availNetListIt += Marshal.SizeOf(typeof (WlanInternSsidEntry));
				}
				return ssidEntries;
			}
			finally
			{
				WlanInterop.FreeMemory(availNetListPtr);
			}
		}
Exemplo n.º 17
0
		internal static void Scan(Nic target)
		{
			ThrowIfError(WlanInterop.Scan(_handle, Guid.Parse(target.Raw.NetworkInterface.Id), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
		}
Exemplo n.º 18
0
		private static void SetOpCode(Nic nic, WlanInternOpcode opCode, int value, out int errorCode)
		{
			IntPtr valuePtr = Marshal.AllocHGlobal(sizeof (int));
			Marshal.WriteInt32(valuePtr, value);
			try
			{
				errorCode = WlanInterop.SetInterface(_handle, Guid.Parse(nic.Raw.NetworkInterface.Id), opCode, sizeof (int), valuePtr, IntPtr.Zero);
			}
			finally
			{
				Marshal.FreeHGlobal(valuePtr);
			}
		}
Exemplo n.º 19
0
		/// <summary>Retrieves the basic service sets (BSS) list of all available networks.</summary>
		internal static WlanInternBssEntry[] GetBssList(Nic nic)
		{
			int error;
			var result = GetBssList(nic, out error);
			ThrowIfError(error);
			return result;
		}
Exemplo n.º 20
0
				public static RecordAAAA[] Get(string hostname, IPAddress dnsServer, Nic localNic, int attempts = 2, int timeout = 1000)
				{
					return Get(hostname, dnsServer, localNic.Ip.GetPreferredSenderAddress(dnsServer), attempts, timeout);
				}
Exemplo n.º 21
0
		internal static void TryScan(Nic target)
		{
			WlanInterop.Scan(_handle, Guid.Parse(target.Raw.NetworkInterface.Id), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
		}
Exemplo n.º 22
0
		/// <summary>Gets a parameter of the interface whose data type is <see cref="int" />.</summary>
		internal static int TryGetOpCode(Nic nic, WlanInternOpcode opCode)
		{
			int error;
			var result = GetOpCode(nic, opCode, out error);
			return result;
		}
Exemplo n.º 23
0
		public void Initialize(Nic targetNic)
		{
			StopTracking();
			Result.Clear();
			Result.SetTargetNic(targetNic);
		}