private void CalculateIPv4SubnetAction() { IsDetailsVisible = false; string[] subnet = Subnet.Trim().Split('/'); string subnetmask = subnet[1]; // Convert CIDR to subnetmask if (subnetmask.Length < 3) { subnetmask = Subnetmask.GetFromCidr(int.Parse(subnet[1])).Subnetmask; } SubnetInfo subnetInfo = Models.Network.Subnet.CalculateIPv4Subnet(IPAddress.Parse(subnet[0]), IPAddress.Parse(subnetmask)); DetailsNetworkAddress = subnetInfo.NetworkAddress; DetailsBroadcast = subnetInfo.Broadcast; DetailsSubnetmask = subnetInfo.Subnetmask; DetailsCIDR = subnetInfo.CIDR; DetailsIPAddresses = subnetInfo.IPAddresses; DetailsFirstIPAddress = subnetInfo.HostFirstIP; DetailsLastIPAddress = subnetInfo.HostLastIP; DetailsHosts = subnetInfo.Hosts; IsDetailsVisible = true; SubnetHistory = new List <string>(HistoryListHelper.Modify(SubnetHistory, Subnet, SettingsManager.Current.Application_HistoryListEntries)); }
private async void StartScan() { DisplayStatusMessage = false; IsScanRunning = true; PreparingScan = true; // Measure the time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; IPScanResult.Clear(); HostsFound = 0; IPAddress[] ipAddresses; cancellationTokenSource = new CancellationTokenSource(); try { // Create a list of all ip addresses ipAddresses = await IPScanRangeHelper.ConvertIPRangeToIPAddressesAsync(IPRange, cancellationTokenSource.Token); } catch (OperationCanceledException) { IpScanner_UserHasCanceled(this, EventArgs.Empty); return; } IPAddressesToScan = ipAddresses.Length; IPAddressesScanned = 0; PreparingScan = false; // Add the range to the history IPRangeHistory = new List <string>(HistoryListHelper.Modify(IPRangeHistory, IPRange, SettingsManager.Current.Application_HistoryListEntries)); IPScannerOptions ipScannerOptions = new IPScannerOptions { Threads = SettingsManager.Current.IPScanner_Threads, Timeout = SettingsManager.Current.IPScanner_Timeout, Buffer = new byte[SettingsManager.Current.IPScanner_Buffer], Attempts = SettingsManager.Current.IPScanner_Attempts, ResolveHostname = SettingsManager.Current.IPScanner_ResolveHostname, ResolveMACAddress = SettingsManager.Current.IPScanner_ResolveMACAddress }; IPScanner ipScanner = new IPScanner(); ipScanner.HostFound += IpScanner_HostFound; ipScanner.ScanComplete += IpScanner_ScanComplete; ipScanner.ProgressChanged += IpScanner_ProgressChanged; ipScanner.UserHasCanceled += IpScanner_UserHasCanceled; ipScanner.ScanAsync(ipAddresses, ipScannerOptions, cancellationTokenSource.Token); }
private async void StartSplit() { DisplayStatusMessage = false; IsSplitRunning = true; SplitResult.Clear(); string[] subnetSplit = Subnet.Trim().Split('/'); string subnetmask = subnetSplit[1]; // Convert CIDR to subnetmask if (subnetmask.Length < 3) { subnetmask = Subnetmask.GetFromCidr(int.Parse(subnetSplit[1])).Subnetmask; } string newSubnetmask = NewSubnetmaskOrCIDR.TrimStart('/'); if (newSubnetmask.Length < 3) { newSubnetmask = Subnetmask.GetFromCidr(int.Parse(newSubnetmask)).Subnetmask; } // Add history SubnetHistory = new List <string>(HistoryListHelper.Modify(SubnetHistory, Subnet, SettingsManager.Current.Application_HistoryListEntries)); NewSubnetmaskOrCIDRHistory = new List <string>(HistoryListHelper.Modify(NewSubnetmaskOrCIDRHistory, NewSubnetmaskOrCIDR, SettingsManager.Current.Application_HistoryListEntries)); cancellationTokenSource = new CancellationTokenSource(); try { foreach (SubnetInfo subnetInfo in await Models.Network.Subnet.SplitIPv4SubnetAsync(IPAddress.Parse(subnetSplit[0]), IPAddress.Parse(subnetmask), IPAddress.Parse(newSubnetmask), cancellationTokenSource.Token)) { SplitResult.Add(subnetInfo); } } catch (OperationCanceledException) { StatusMessage = Application.Current.Resources["String_CanceledByUser"] as string; DisplayStatusMessage = true; } CancelSplit = false; IsSplitRunning = false; }
private async void OUILookupAction() { IsLookupRunning = true; OUILookupResult.Clear(); List <string> vendors = new List <string>(); foreach (string macAddressOrVendor in MACAddressOrVendor.Split(';')) { string macAddressOrVendor1 = macAddressOrVendor.Trim(); if (Regex.IsMatch(macAddressOrVendor1, RegexHelper.MACAddressRegex) || Regex.IsMatch(macAddressOrVendor1, RegexHelper.MACAddressFirst3BytesRegex)) { foreach (OUIInfo info in await OUILookup.LookupAsync(macAddressOrVendor1)) { OUILookupResult.Add(info); } } else { vendors.Add(macAddressOrVendor1); } } foreach (OUIInfo info in await OUILookup.LookupByVendorAsync(vendors)) { OUILookupResult.Add(info); } if (OUILookupResult.Count == 0) { NoVendorFound = true; } else { MACAddressOrVendorHistory = new List <string>(HistoryListHelper.Modify(MACAddressOrVendorHistory, MACAddressOrVendor, SettingsManager.Current.Application_HistoryListEntries)); NoVendorFound = false; } IsLookupRunning = false; }
private async void Check() { DisplayStatusMessage = false; IsCheckRunning = true; // Measure time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; Headers = null; HeadersCount = 0; try { WebHeaderCollection headers = await HTTPHeaders.GetHeadersAsync(new Uri(WebsiteUri)); Headers = headers.ToString(); HeadersCount = headers.Count; } catch (Exception ex) { StatusMessage = ex.Message; DisplayStatusMessage = true; } WebsiteUriHistory = new List <string>(HistoryListHelper.Modify(WebsiteUriHistory, WebsiteUri, SettingsManager.Current.Application_HistoryListEntries)); // Stop timer and stopwatch stopwatch.Stop(); dispatcherTimer.Stop(); Duration = stopwatch.Elapsed; EndTime = DateTime.Now; stopwatch.Reset(); IsCheckRunning = false; }
private void StartLookup() { DisplayStatusMessage = false; IsLookupRunning = true; // Reset statistic DNSServerAndPort = string.Empty; Questions = 0; Answers = 0; Authorities = 0; Additionals = 0; MessageSize = 0; // Measure the time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; // Reset the latest results LookupResult.Clear(); HostHistory = new List <string>(HistoryListHelper.Modify(HostHistory, Host, SettingsManager.Current.Application_HistoryListEntries)); DNSLookupOptions DNSLookupOptions = new DNSLookupOptions(); if (SettingsManager.Current.DNSLookup_UseCustomDNSServer) { if (!string.IsNullOrEmpty(SettingsManager.Current.DNSLookup_CustomDNSServer)) { DNSLookupOptions.UseCustomDNSServer = SettingsManager.Current.DNSLookup_UseCustomDNSServer; DNSLookupOptions.CustomDNSServer = SettingsManager.Current.DNSLookup_CustomDNSServer; } else { StatusMessage = Application.Current.Resources["String_CustomDNSServerIsEmptyCheckYourSettingsUseWindowsOwnDNSServer"] as string; DisplayStatusMessage = true; } } DNSLookupOptions.Class = SettingsManager.Current.DNSLookup_Class; DNSLookupOptions.Type = Type; DNSLookupOptions.Recursion = SettingsManager.Current.DNSLookup_Recursion; DNSLookupOptions.UseResolverCache = SettingsManager.Current.DNSLookup_UseResolverCache; DNSLookupOptions.TransportType = SettingsManager.Current.DNSLookup_TransportType; DNSLookupOptions.Attempts = SettingsManager.Current.DNSLookup_Attempts; DNSLookupOptions.Timeout = SettingsManager.Current.DNSLookup_Timeout; DNSLookupOptions.ResolveCNAME = SettingsManager.Current.DNSLookup_ResolveCNAME; DNSLookup DNSLookup = new DNSLookup(); DNSLookup.RecordReceived += DNSLookup_RecordReceived; DNSLookup.LookupError += DNSLookup_LookupError; DNSLookup.LookupComplete += DNSLookup_LookupComplete; string hostnameOrIPAddress = Host; string dnsSuffix = string.Empty; // Detect hostname (usually they don't contain ".") if (Host.IndexOf(".", StringComparison.OrdinalIgnoreCase) == -1) { if (SettingsManager.Current.DNSLookup_AddDNSSuffix) { if (SettingsManager.Current.DNSLookup_UseCustomDNSSuffix) { dnsSuffix = SettingsManager.Current.DNSLookup_CustomDNSSuffix; } else { dnsSuffix = IPGlobalProperties.GetIPGlobalProperties().DomainName; } } } // Append dns suffix to hostname if (!string.IsNullOrEmpty(dnsSuffix)) { hostnameOrIPAddress += string.Format("{0}{1}", dnsSuffix.StartsWith(".") ? "" : ".", dnsSuffix); } DNSLookup.LookupAsync(hostnameOrIPAddress, DNSLookupOptions); }
private async void PortLookupAction() { IsPortLookupRunning = true; PortLookupResult.Clear(); List <string> portsByService = new List <string>(); foreach (string portOrService in PortsOrService.Split(';')) { string portOrService1 = portOrService.Trim(); if (portOrService1.Contains("-")) { string[] portRange = portOrService1.Split('-'); if (int.TryParse(portRange[0], out int startPort) && int.TryParse(portRange[1], out int endPort)) { if ((startPort > 0) && (startPort < 65536) && (endPort > 0) && (endPort < 65536) && (startPort < endPort)) { for (int i = startPort; i < endPort + 1; i++) { foreach (PortLookupInfo info in await PortLookup.LookupAsync(i)) { PortLookupResult.Add(info); } } } else { portsByService.Add(portOrService1); } } else { portsByService.Add(portOrService1); } } else { if (int.TryParse(portOrService1, out int port)) { if (port > 0 && port < 65536) { foreach (PortLookupInfo info in await PortLookup.LookupAsync(port)) { PortLookupResult.Add(info); } } else { portsByService.Add(portOrService1); } } else { portsByService.Add(portOrService1); } } } foreach (PortLookupInfo info in await PortLookup.LookupByServiceAsync(portsByService)) { PortLookupResult.Add(info); } if (PortLookupResult.Count == 0) { NoPortsFound = true; } else { PortsHistory = new List <string>(HistoryListHelper.Modify(PortsHistory, PortsOrService, SettingsManager.Current.Application_HistoryListEntries)); NoPortsFound = false; } IsPortLookupRunning = false; }
private async void StartTrace() { DisplayStatusMessage = false; IsTraceRunning = true; // Measure the time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; TraceResult.Clear(); Hops = 0; cancellationTokenSource = new CancellationTokenSource(); // Try to parse the string into an IP-Address IPAddress.TryParse(Hostname, out IPAddress ipAddress); try { // Try to resolve the hostname if (ipAddress == null) { IPHostEntry ipHostEntrys = await Dns.GetHostEntryAsync(Hostname); foreach (IPAddress ip in ipHostEntrys.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork && SettingsManager.Current.Traceroute_ResolveHostnamePreferIPv4) { ipAddress = ip; continue; } else if (ip.AddressFamily == AddressFamily.InterNetworkV6 && !SettingsManager.Current.Traceroute_ResolveHostnamePreferIPv4) { ipAddress = ip; continue; } } // Fallback --> If we could not resolve our prefered ip protocol if (ipAddress == null) { foreach (IPAddress ip in ipHostEntrys.AddressList) { ipAddress = ip; continue; } } } TracerouteOptions tracerouteOptions = new TracerouteOptions { Timeout = SettingsManager.Current.Traceroute_Timeout, Buffer = SettingsManager.Current.Traceroute_Buffer, MaximumHops = SettingsManager.Current.Traceroute_MaximumHops, DontFragement = true, ResolveHostname = SettingsManager.Current.Traceroute_ResolveHostname }; Traceroute traceroute = new Traceroute(); traceroute.HopReceived += Traceroute_HopReceived; traceroute.TraceComplete += Traceroute_TraceComplete; traceroute.MaximumHopsReached += Traceroute_MaximumHopsReached; traceroute.UserHasCanceled += Traceroute_UserHasCanceled; traceroute.TraceAsync(ipAddress, tracerouteOptions, cancellationTokenSource.Token); // Add the hostname or ip address to the history HostnameHistory = new List <string>(HistoryListHelper.Modify(HostnameHistory, Hostname, SettingsManager.Current.Application_HistoryListEntries)); } catch (SocketException) // This will catch DNS resolve errors { TracerouteFinished(); StatusMessage = string.Format(Application.Current.Resources["String_CouldNotResolveHostnameFor"] as string, Hostname); DisplayStatusMessage = true; } catch (Exception ex) // This will catch any exception { TracerouteFinished(); StatusMessage = ex.Message; DisplayStatusMessage = true; } }
private async void StartScan() { DisplayStatusMessage = false; StatusMessage = string.Empty; IsScanRunning = true; PreparingScan = true; // Measure the time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; PortScanResult.Clear(); PortsOpen = 0; cancellationTokenSource = new CancellationTokenSource(); string[] hosts = Hostname.Split(';'); List <Tuple <IPAddress, string> > hostData = new List <Tuple <IPAddress, string> >(); for (int i = 0; i < hosts.Length; i++) { string host = hosts[i].Trim(); string hostname = string.Empty; IPAddress.TryParse(host, out IPAddress ipAddress); try { // Resolve DNS // Try to resolve the hostname if (ipAddress == null) { IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(host); foreach (IPAddress ip in ipHostEntry.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork && SettingsManager.Current.PortScanner_ResolveHostnamePreferIPv4) { ipAddress = ip; continue; } else if (ip.AddressFamily == AddressFamily.InterNetworkV6 && !SettingsManager.Current.PortScanner_ResolveHostnamePreferIPv4) { ipAddress = ip; continue; } } // Fallback --> If we could not resolve our prefered ip protocol if (ipAddress == null) { foreach (IPAddress ip in ipHostEntry.AddressList) { ipAddress = ip; continue; } } hostname = host; } else { try { IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(ipAddress); hostname = ipHostEntry.HostName; } catch { } } } catch (SocketException) // This will catch DNS resolve errors { if (!string.IsNullOrEmpty(StatusMessage)) { StatusMessage += Environment.NewLine; } StatusMessage += string.Format(Application.Current.Resources["String_CouldNotResolveHostnameFor"] as string, host); DisplayStatusMessage = true; continue; } hostData.Add(Tuple.Create(ipAddress, hostname)); } if (hostData.Count == 0) { StatusMessage += Environment.NewLine + Application.Current.Resources["String_NothingToDoCheckYourInput"] as string; DisplayStatusMessage = true; ScanFinished(); return; } int[] ports = await PortRangeHelper.ConvertPortRangeToIntArrayAsync(Ports); try { PortsToScan = ports.Length * hostData.Count; PortsScanned = 0; PreparingScan = false; HostnameHistory = new List <string>(HistoryListHelper.Modify(HostnameHistory, Hostname, SettingsManager.Current.Application_HistoryListEntries)); PortsHistory = new List <string>(HistoryListHelper.Modify(PortsHistory, Ports, SettingsManager.Current.Application_HistoryListEntries)); PortScannerOptions portScannerOptions = new PortScannerOptions { Threads = SettingsManager.Current.PortScanner_Threads, ShowClosed = SettingsManager.Current.PortScanner_ShowClosed, Timeout = SettingsManager.Current.PortScanner_Timeout }; PortScanner portScanner = new PortScanner(); portScanner.PortScanned += PortScanner_PortScanned; portScanner.ScanComplete += PortScanner_ScanComplete; portScanner.ProgressChanged += PortScanner_ProgressChanged; portScanner.UserHasCanceled += PortScanner_UserHasCanceled; portScanner.ScanAsync(hostData, ports, portScannerOptions, cancellationTokenSource.Token); } catch (Exception ex) // This will catch any exception { StatusMessage = ex.Message; DisplayStatusMessage = true; ScanFinished(); } }
private async void StartPing() { DisplayStatusMessage = false; IsPingRunning = true; // Measure the time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; // Reset the latest results PingResult.Clear(); PingsTransmitted = 0; PingsReceived = 0; PingsLost = 0; AverageTime = 0; MinimumTime = 0; MaximumTime = 0; // Try to parse the string into an IP-Address IPAddress.TryParse(HostnameOrIPAddress, out IPAddress ipAddress); try { // Try to resolve the hostname if (ipAddress == null) { IPHostEntry ipHostEntrys = await Dns.GetHostEntryAsync(HostnameOrIPAddress); foreach (IPAddress ip in ipHostEntrys.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork && SettingsManager.Current.Ping_ResolveHostnamePreferIPv4) { ipAddress = ip; continue; } else if (ip.AddressFamily == AddressFamily.InterNetworkV6 && !SettingsManager.Current.Ping_ResolveHostnamePreferIPv4) { ipAddress = ip; continue; } } // Fallback --> If we could not resolve our prefered ip protocol for the hostname if (ipAddress == null) { foreach (IPAddress ip in ipHostEntrys.AddressList) { ipAddress = ip; continue; } } } } catch (SocketException) // This will catch DNS resolve errors { PingFinished(); StatusMessage = string.Format(Application.Current.Resources["String_CouldNotResolveHostnameFor"] as string, HostnameOrIPAddress); DisplayStatusMessage = true; return; } // Add the hostname or ip address to the history HostnameOrIPAddressHistory = new List <string>(HistoryListHelper.Modify(HostnameOrIPAddressHistory, HostnameOrIPAddress, SettingsManager.Current.Application_HistoryListEntries)); cancellationTokenSource = new CancellationTokenSource(); PingOptions pingOptions = new PingOptions() { Attempts = SettingsManager.Current.Ping_Attempts, Timeout = SettingsManager.Current.Ping_Timeout, Buffer = new byte[SettingsManager.Current.Ping_Buffer], TTL = SettingsManager.Current.Ping_TTL, DontFragment = SettingsManager.Current.Ping_DontFragment, WaitTime = SettingsManager.Current.Ping_WaitTime, ExceptionCancelCount = SettingsManager.Current.Ping_ExceptionCancelCount }; Ping ping = new Ping(); ping.PingReceived += Ping_PingReceived; ping.PingCompleted += Ping_PingCompleted; ping.PingException += Ping_PingException; ping.UserHasCanceled += Ping_UserHasCanceled; ping.SendAsync(ipAddress, pingOptions, cancellationTokenSource.Token); }