Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Scripts/Create-WhoisServerListFromWebAndWhois.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Filepath in the resources
[string]$OutFilePath = Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath "Source\NETworkManager\Resources\WhoisServers.xml"

$IANA_TLDs = (Invoke-WebRequest -Uri "https://data.iana.org/TLD/tlds-alpha-by-domain.txt").Content -split "[`r|`n]"

# Create xml document
[xml]$Document = New-Object System.Xml.XmlDocument
$Declaration = $Document.CreateXmlDeclaration("1.0", "UTF-8", $null)

[void]$Document.AppendChild($Declaration)

# Description
$Description = @"
Whois servers by domain from IANA
Generated $(Get-Date)
"@

[void]$Document.AppendChild($Document.CreateComment($Description))

# Root node
$RootNode = $Document.CreateNode("element", "WhoisServers", $null)

$ProgressCount = 0

foreach($Tld in $IANA_TLDs)
{
if($Tld.StartsWith("#"))
{
continue
}

$currentTld = $Tld.Trim()

$tcpClient = New-Object System.Net.Sockets.TcpClient("whois.iana.org", 43)

$networkStream= $tcpClient.GetStream()

$bufferedStream = New-Object System.IO.BufferedStream($networkStream)

$streamWriter = New-Object System.IO.StreamWriter($bufferedStream)

$streamWriter.WriteLine($currentTld)
$streamWriter.Flush()

$streamReader = New-Object System.IO.StreamReader($bufferedStream)

$stringBuilder = New-Object System.Text.StringBuilder

while(!$streamReader.EndOfStream)
{
$stringBuilder.Append($streamReader.ReadLine())
}

$WhoisServer = (($stringBuilder.ToString() -split "whois:")[1] -split "status:")[0].Trim()

$WhoisServerNode = $Document.CreateNode("element", "WhoisServer", $null)

$TldElement = $Document.CreateElement("TLD")
$TldElement.InnerText = $currentTld
[void]$WhoisServerNode.AppendChild($TldElement)

$ServerElement = $Document.CreateElement("Server")
$ServerElement.InnerText = $WhoisServer
[void]$WhoisServerNode.AppendChild($ServerElement)

[void]$RootNode.AppendChild($WhoisServerNode)

Write-Host -Object "Progress: $ProgressCount from $($IANA_TLDs.Count)"
$ProgressCount ++
}

[void]$Document.AppendChild($RootNode)
$Document.Save($OutFilePath)
24 changes: 15 additions & 9 deletions Source/NETworkManager/ApplicationViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ public static string GetTranslatedNameByName(Name name)
case Name.SNMP:
return Resources.Localization.Strings.SNMP;
case Name.WakeOnLAN:
return Resources.Localization.Strings.WakeOnLAN;
case Name.HTTPHeaders:
return Resources.Localization.Strings.HTTPHeaders;
return Resources.Localization.Strings.WakeOnLAN;
case Name.SubnetCalculator:
return Resources.Localization.Strings.SubnetCalculator;
case Name.Lookup:
return Resources.Localization.Strings.Lookup;
case Name.Whois:
return Resources.Localization.Strings.Whois;
case Name.HTTPHeaders:
return Resources.Localization.Strings.HTTPHeaders;
case Name.Connections:
return Resources.Localization.Strings.Connections;
case Name.Listeners:
return Resources.Localization.Strings.Listeners;
case Name.ARPTable:
return Resources.Localization.Strings.ARPTable;
return Resources.Localization.Strings.ARPTable;
default:
return "Name not found!";
}
Expand Down Expand Up @@ -98,15 +100,18 @@ public static Canvas GetIconByName(Name name)
case Name.WakeOnLAN:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.Power });
break;
case Name.HTTPHeaders:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.Web });
break;
case Name.SubnetCalculator:
canvas.Children.Add(new PackIconModern { Kind = PackIconModernKind.Calculator });
break;
case Name.Lookup:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.Magnify });
break;
case Name.Whois:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.CloudSearchOutline });
break;
case Name.HTTPHeaders:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.Web });
break;
case Name.Connections:
canvas.Children.Add(new PackIconModern { Kind = PackIconModernKind.Connect });
break;
Expand Down Expand Up @@ -136,10 +141,11 @@ public enum Name
RemoteDesktop,
PuTTY,
SNMP,
WakeOnLAN,
HTTPHeaders,
WakeOnLAN,
SubnetCalculator,
Lookup,
Whois,
HTTPHeaders,
Connections,
Listeners,
ARPTable
Expand Down
3 changes: 3 additions & 0 deletions Source/NETworkManager/Controls/DragablzTabHostWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
break;
case ApplicationViewManager.Name.Lookup:
break;
case ApplicationViewManager.Name.Whois:
((WhoisView)((DragablzTabItem)args.DragablzItem.Content).View).CloseTab();
break;
case ApplicationViewManager.Name.Connections:
break;
case ApplicationViewManager.Name.Listeners:
Expand Down
29 changes: 21 additions & 8 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Windows.Markup;
using NETworkManager.Models.Update;
using NETworkManager.Models.Documentation;
using NETworkManager.Models.Network;
using ContextMenu = System.Windows.Controls.ContextMenu;

namespace NETworkManager
Expand Down Expand Up @@ -248,6 +249,10 @@ public MainWindow()
// Language Meta
LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(LocalizationManager.Culture.IetfLanguageTag)));

// Update settings
if (AssemblyManager.Current.Version > new Version(SettingsManager.Current.SettingsVersion))
SettingsManager.Update(AssemblyManager.Current.Version, new Version(SettingsManager.Current.SettingsVersion));

// Load appearance
AppearanceManager.Load();

Expand Down Expand Up @@ -306,7 +311,7 @@ protected override async void OnContentRendered(EventArgs e)
if (CommandLineManager.Current.Autostart && SettingsManager.Current.Autostart_StartMinimizedInTray)
HideWindowToTray();

// Chech for updates...
// Search for updates...
if (SettingsManager.Current.Update_CheckForUpdatesAtStartup)
CheckForUpdates();
}
Expand Down Expand Up @@ -420,6 +425,7 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
private SubnetCalculatorHostView _subnetCalculatorHostView;
private HTTPHeadersHostView _httpHeadersHostView;
private LookupHostView _lookupHostView;
private WhoisHostView _whoisHostView;
private ConnectionsView _connectionsView;
private ListenersView _listenersView;
private ARPTableView _arpTableView;
Expand Down Expand Up @@ -495,13 +501,6 @@ private void ChangeApplicationView(ApplicationViewManager.Name name)

ContentControlApplication.Content = _wakeOnLanView;
break;

case ApplicationViewManager.Name.HTTPHeaders:
if (_httpHeadersHostView == null)
_httpHeadersHostView = new HTTPHeadersHostView();

ContentControlApplication.Content = _httpHeadersHostView;
break;
case ApplicationViewManager.Name.SubnetCalculator:
if (_subnetCalculatorHostView == null)
_subnetCalculatorHostView = new SubnetCalculatorHostView();
Expand All @@ -514,6 +513,18 @@ private void ChangeApplicationView(ApplicationViewManager.Name name)

ContentControlApplication.Content = _lookupHostView;
break;
case ApplicationViewManager.Name.Whois:
if(_whoisHostView ==null)
_whoisHostView = new WhoisHostView();

ContentControlApplication.Content = _whoisHostView;
break;
case ApplicationViewManager.Name.HTTPHeaders:
if (_httpHeadersHostView == null)
_httpHeadersHostView = new HTTPHeadersHostView();

ContentControlApplication.Content = _httpHeadersHostView;
break;
case ApplicationViewManager.Name.Connections:
if (_connectionsView == null)
_connectionsView = new ConnectionsView();
Expand Down Expand Up @@ -580,6 +591,8 @@ private void RefreshApplicationView(ApplicationViewManager.Name name)
break;
case ApplicationViewManager.Name.Lookup:
break;
case ApplicationViewManager.Name.Whois:
break;
case ApplicationViewManager.Name.Connections:
break;
case ApplicationViewManager.Name.Listeners:
Expand Down
81 changes: 81 additions & 0 deletions Source/NETworkManager/Models/Network/Whois.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using NETworkManager.Models.Settings;

namespace NETworkManager.Models.Network
{
public class Whois
{
#region Variables
private static readonly string WhoisServerFilePath =
Path.Combine(ConfigurationManager.Current.ExecutionPath, "Resources", "WhoisServers.xml");

private static readonly List<WhoisServerInfo> WhoisServerList;
private static readonly Lookup<string, WhoisServerInfo> WhoisServers;
#endregion

#region Constructor

static Whois()
{
var document = new XmlDocument();
document.Load(WhoisServerFilePath);

WhoisServerList = new List<WhoisServerInfo>();

foreach (XmlNode node in document.SelectNodes("/WhoisServers/WhoisServer"))
{
if (node == null)
continue;

WhoisServerList.Add(new WhoisServerInfo(node.SelectSingleNode("Server")?.InnerText, node.SelectSingleNode("TLD")?.InnerText));
}

WhoisServers = (Lookup<string, WhoisServerInfo>)WhoisServerList.ToLookup(x => x.Tld);
}
#endregion

#region Methods
public static Task<string> QueryAsync(string domain, string whoisServer)
{
return Task.Run(() => Query(domain, whoisServer));
}

public static string Query(string domain, string whoisServer)
{
var tcpClient = new TcpClient(whoisServer, 43);

var networkStream = tcpClient.GetStream();

var bufferedStream = new BufferedStream(networkStream);

var streamWriter = new StreamWriter(bufferedStream);

streamWriter.WriteLine(domain);
streamWriter.Flush();

var streamReader = new StreamReader(bufferedStream);

var stringBuilder = new StringBuilder();

while (!streamReader.EndOfStream)
stringBuilder.AppendLine(streamReader.ReadLine());

return stringBuilder.ToString();
}

public static string GetWhoisServer(string domain)
{
var domainParts = domain.Split('.');

// TLD to upper because the lookup is case sensitive
return WhoisServers[domainParts[domainParts.Length - 1].ToUpper()].FirstOrDefault()?.Server;
}
#endregion
}
}
14 changes: 14 additions & 0 deletions Source/NETworkManager/Models/Network/WhoisServerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NETworkManager.Models.Network
{
public class WhoisServerInfo
{
public string Server { get; set; }
public string Tld { get; set; }

public WhoisServerInfo(string server, string tld)
{
Server = server;
Tld = tld;
}
}
}
63 changes: 62 additions & 1 deletion Source/NETworkManager/Models/Settings/SettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,22 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName

#region Variables
[XmlIgnore] public bool SettingsChanged { get; set; }
#region General

private string _settingsVersion = "0.0.0.0";
public string SettingsVersion
{
get => _settingsVersion;
set
{
if(value == _settingsVersion)
return;

_settingsVersion = value;
SettingsChanged = true;
}
}

#region General
// General
private ApplicationViewManager.Name _general_DefaultApplicationViewName = ApplicationViewManager.Name.NetworkInterface;
public ApplicationViewManager.Name General_DefaultApplicationViewName
Expand Down Expand Up @@ -2330,6 +2344,53 @@ public ObservableCollection<string> Lookup_Port_PortsHistory
}
#endregion

#region Whois
private ObservableCollection<string> _whois_DomainHistory = new ObservableCollection<string>();
public ObservableCollection<string> Whois_DomainHistory
{
get => _whois_DomainHistory;
set
{
if (value == _whois_DomainHistory)
return;

_whois_DomainHistory = value;
SettingsChanged = true;
}
}

private bool _whois_ExpandStatistics = true;
public bool Whois_ExpandStatistics
{
get => _whois_ExpandStatistics;
set
{
if (value == _whois_ExpandStatistics)
return;

_whois_ExpandStatistics = value;
SettingsChanged = true;
}
}

private bool _whois_ShowStatistics = true;
public bool Whois_ShowStatistics
{
get => _whois_ShowStatistics;
set
{
if (value == _whois_ShowStatistics)
return;

_whois_ShowStatistics = value;

OnPropertyChanged();

SettingsChanged = true;
}
}
#endregion

#region Connections
private bool _connections_AutoRefresh;
public bool Connections_AutoRefresh
Expand Down
Loading