Skip to content

Commit

Permalink
Updated to support ipv4 addresses
Browse files Browse the repository at this point in the history
Updated to support ipv4 addresses
  • Loading branch information
ryanries committed Feb 20, 2015
1 parent 12bb724 commit 79f6d6b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
35 changes: 25 additions & 10 deletions SharpTLSScan/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ static void Main(string[] args)
#region Argument validation, DNS resolution, and TCP connectivity
UInt16 portNum = 443;
string hostName = string.Empty;
IPAddress ipAddress;

Regex hostnameRegex = new Regex(@"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$", RegexOptions.IgnoreCase);

if (args.Length != 1 & args.Length != 2)
if ((args.Length != 1) & (args.Length != 2))
PrintHelpMessageAndExit();

hostName = args[0].Split(':')[0];
Expand All @@ -64,24 +65,38 @@ static void Main(string[] args)
else
PrintHelpMessageAndExit();

Console.WriteLine("Scanning " + hostName + " on port " + portNum + "...");

IPHostEntry ipHostEntry;

IPHostEntry ipHostEntry = null;
try
{
ipHostEntry = Dns.GetHostEntry(hostName);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ERROR: " + ex.Message);
Console.ResetColor();
return;
// DNS didn't work, maybe it's an IP address?
if (IPAddress.TryParse(hostName, out ipAddress) == false)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ERROR: " + ex.Message);
Console.ResetColor();
return;
}
else
{
hostName = ipAddress.ToString();
}
}

Console.WriteLine("Scanning " + hostName + " on port " + portNum + "...");

if (ipHostEntry != null)
{
Console.WriteLine(hostName + " resolved to " + ipHostEntry.AddressList.Length + " IP addresses:");
foreach (var ip in ipHostEntry.AddressList)
Console.WriteLine(" " + ip);
}

Console.WriteLine(hostName + " resolved to " + ipHostEntry.AddressList.Length + " IP addresses:");
foreach (var ip in ipHostEntry.AddressList)
Console.WriteLine(" " + ip);

try
{
Expand Down
6 changes: 3 additions & 3 deletions SharpTLSScan/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Ryan Ries | myotherpcisacloud.com")]
[assembly: AssemblyProduct("SharpTLSScan")]
[assembly: AssemblyCopyright("Copyright © Ryan Ries | myotherpcisacloud.com 2014")]
[assembly: AssemblyCopyright("Copyright © Ryan Ries | myotherpcisacloud.com 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]

0 comments on commit 79f6d6b

Please sign in to comment.