Added solution files
This commit is contained in:
parent
3ac20528d7
commit
3880125939
22
DNSq.sln
Normal file
22
DNSq.sln
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DNSq", "DNSq\DNSq.csproj", "{BBF6E069-6C4B-4597-B640-73753B5A7C5B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BBF6E069-6C4B-4597-B640-73753B5A7C5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BBF6E069-6C4B-4597-B640-73753B5A7C5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BBF6E069-6C4B-4597-B640-73753B5A7C5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BBF6E069-6C4B-4597-B640-73753B5A7C5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
79
DNSq/DNSq.csproj
Normal file
79
DNSq/DNSq.csproj
Normal file
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BBF6E069-6C4B-4597-B640-73753B5A7C5B}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DNSq</RootNamespace>
|
||||
<AssemblyName>DNSq</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
288
DNSq/Program.cs
Normal file
288
DNSq/Program.cs
Normal file
@ -0,0 +1,288 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
namespace DNSq
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string commandArg;
|
||||
try
|
||||
{
|
||||
commandArg = args[0].ToLower();
|
||||
}
|
||||
catch
|
||||
{
|
||||
commandArg = null;
|
||||
}
|
||||
int debugFlag = Array.IndexOf(args, "-d");
|
||||
int rangeFlag = Array.IndexOf(args, "-r");
|
||||
int acceptFlag = Array.IndexOf(args, "-a");
|
||||
|
||||
if (commandArg == "/?" || commandArg == "help" || commandArg == null)
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("DNSq provides command-line Dns queries including Domain-name lookups and reverse Ip Address lookups");
|
||||
Console.WriteLine("Usage:");
|
||||
Console.WriteLine("DNSq [Ip Address or Domain Name] [-d]");
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("Options:");
|
||||
Console.WriteLine("\t /? or help | This page");
|
||||
Console.WriteLine("\t [IpAddress|Dns] (repeat) | Performs a Dns query to the provided");
|
||||
Console.WriteLine("\t | address(es). Repeatable");
|
||||
Console.WriteLine("\t -d | Provides additional debug messages");
|
||||
Console.WriteLine("\t -r [IpAddress]-[IpAddress] | Queries a range of Ip Addresses");
|
||||
Console.WriteLine("\t -a | Automatically accepts any message");
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("Note that it is not possible to return all hostnames associated with an address, it may not be possible on some addresses altogether.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("Collecting Dns Data...");
|
||||
bool isRange = false;
|
||||
foreach (string s in args)
|
||||
{
|
||||
if (!s.Contains("-"))
|
||||
{
|
||||
IPAddress oIp;
|
||||
string outDns = "";
|
||||
string outIp = "";
|
||||
bool isIp = false;
|
||||
int hostnameLength = 0;
|
||||
if (IPAddress.TryParse(s, out oIp))
|
||||
{
|
||||
// Provided string is an Ip Address
|
||||
try
|
||||
{
|
||||
outDns = Dns.GetHostEntry(oIp).HostName;
|
||||
outIp = oIp.ToString();
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException e)
|
||||
{
|
||||
outIp = "The specified host does not exist. \n";
|
||||
if (debugFlag != -1)
|
||||
{
|
||||
outIp += "Exception details are " + e;
|
||||
}
|
||||
}
|
||||
|
||||
isIp = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
int index = 0;
|
||||
foreach (IPAddress ip in Dns.GetHostEntry(s).AddressList)
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
outIp += @", ";
|
||||
}
|
||||
outIp = ip.ToString();
|
||||
}
|
||||
outDns = s;
|
||||
isIp = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Input is not a resolveable Dns
|
||||
if (debugFlag != -1)
|
||||
{
|
||||
Console.WriteLine("Input \"{0}\" is not a valid hostname. Exception returned: {1}", s, e.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Input \"{0}\" is not a valid hostname. Run command with -d for more information", s);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
string numberString = "this hostname";
|
||||
if (hostnameLength > 1)
|
||||
{
|
||||
numberString = "these hostnames";
|
||||
}
|
||||
if (isIp)
|
||||
{
|
||||
Console.WriteLine("Dns request to {0} returned {1}: \t{2}", outIp, numberString, outDns);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Dns request to {0} returned this address: \t{1}", outDns, outIp);
|
||||
}
|
||||
}
|
||||
else if (s == "-d")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (s == "-r")
|
||||
{
|
||||
isRange = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isRange)
|
||||
{
|
||||
string trimmed = s.Trim();
|
||||
Console.WriteLine("A range has been supplied, verifying Ip Addresses...");
|
||||
string[] ipMinMax =new string[0];
|
||||
if (trimmed.Contains("-"))
|
||||
{
|
||||
ipMinMax = trimmed.Split('-');
|
||||
}
|
||||
else if(trimmed.Contains(" "))
|
||||
{
|
||||
ipMinMax = trimmed.Split(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
IPAddress firstIp;
|
||||
IPAddress secondIp;
|
||||
IPAddress.TryParse(ipMinMax[0], out firstIp);
|
||||
IPAddress.TryParse(ipMinMax[ipMinMax.Length - 1], out secondIp);
|
||||
Console.WriteLine("Input addresses {0} and {1} verified successfully..", firstIp.ToString(), secondIp.ToString());
|
||||
string[] firstSegments = firstIp.ToString().Split('.');
|
||||
string[] lastSegments = secondIp.ToString().Split('.');
|
||||
|
||||
int[] seg1 = new int[2];
|
||||
int[] seg2 = new int[2];
|
||||
int[] seg3 = new int[2];
|
||||
int[] seg4 = new int[2];
|
||||
|
||||
seg1[0] = Convert.ToInt32(firstSegments[0]);
|
||||
seg2[0] = Convert.ToInt32(firstSegments[1]);
|
||||
seg3[0] = Convert.ToInt32(firstSegments[2]);
|
||||
seg4[0] = Convert.ToInt32(firstSegments[3]);
|
||||
seg1[1] = Convert.ToInt32(lastSegments[0]);
|
||||
seg2[1] = Convert.ToInt32(lastSegments[1]);
|
||||
seg3[1] = Convert.ToInt32(lastSegments[2]);
|
||||
seg4[1] = Convert.ToInt32(lastSegments[3]);
|
||||
|
||||
int seg1diff = Math.Abs(seg1[0] - seg1[1]);
|
||||
int seg2diff = Math.Abs(seg2[0] - seg2[1]);
|
||||
int seg3diff = Math.Abs(seg3[0] - seg3[1]);
|
||||
int seg4diff = Math.Abs(seg4[0] - seg4[1]);
|
||||
|
||||
int rawNumber = seg1diff * 256 * 256 * 256;
|
||||
rawNumber = rawNumber + seg2diff * 256 * 256;
|
||||
rawNumber = rawNumber + seg3diff * 256;
|
||||
rawNumber = rawNumber + seg4diff;
|
||||
//int rawNumber = (((((((seg1diff) + seg2diff) * 256) + seg3diff) * 256) + seg4diff )* 256);
|
||||
|
||||
if(rawNumber > 127)
|
||||
{
|
||||
Console.WriteLine("Warning, you are about to perform a Dns lookup on {0} addressess. This can take a long time.", rawNumber);
|
||||
string byteData = "";
|
||||
if(rawNumber * 20 >= 10000 && rawNumber *20 < 10000000)
|
||||
{
|
||||
byteData = (rawNumber * 20 / 1000).ToString() + "kB";
|
||||
}
|
||||
else if(rawNumber * 20 >= 10000000)
|
||||
{
|
||||
byteData = (rawNumber * 20 / 1000000).ToString() + "MB";
|
||||
}
|
||||
else
|
||||
{
|
||||
byteData = (rawNumber * 20).ToString() + " bytes";
|
||||
}
|
||||
Console.WriteLine("Please note that if you are exporting this data, you are looking at at approximately {0} of data", byteData);
|
||||
Console.WriteLine("Press 'C' to continue, otherwise, press any key to exit.");
|
||||
ConsoleKeyInfo readKey;
|
||||
if (acceptFlag != -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
readKey = Console.ReadKey(true);
|
||||
}
|
||||
if(readKey.Key == ConsoleKey.C || acceptFlag != -1)
|
||||
{
|
||||
Console.WriteLine("You have pressed 'C'. Getting Dns queries for {0} hosts", rawNumber);
|
||||
for(int i = 0; i < rawNumber; i++)
|
||||
{
|
||||
// Dns Lookup Logic
|
||||
string ipCheck = seg1[0] + "." + seg2[0] + "." + seg3[0] + "." + seg4[0];
|
||||
Console.WriteLine("At {0}, Dns returned {1}",ipCheck, Dns.GetHostEntry(ipCheck).HostName);
|
||||
// Increment the Ip
|
||||
if (seg4[0] < 255)
|
||||
{
|
||||
seg4[0]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
seg4[0] = 0;
|
||||
if (seg3[0] < 255)
|
||||
{
|
||||
seg3[0]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
seg3[0] = 0;
|
||||
if (seg2[0] < 255)
|
||||
{
|
||||
seg2[0]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
seg2[0] = 0;
|
||||
if (seg1[0] < 255)
|
||||
{
|
||||
seg1[0]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Segment 1 exceeded maximum value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//int integer = 234;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
throw new Exception("Segment 1 exceeded maximum value");
|
||||
}
|
||||
|
||||
}
|
||||
public static int Lowest(params int[] inputs)
|
||||
{
|
||||
int lowest = inputs[0];
|
||||
int index = 0;
|
||||
int finalIndex = 0;
|
||||
foreach (var input in inputs)
|
||||
{
|
||||
if (input < lowest)
|
||||
{
|
||||
lowest = input;
|
||||
finalIndex = index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
return finalIndex;
|
||||
}
|
||||
}
|
||||
}
|
39
DNSq/Properties/AssemblyInfo.cs
Normal file
39
DNSq/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DNSq")]
|
||||
[assembly: AssemblyDescription("DNS Query")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Precipice Projects")]
|
||||
[assembly: AssemblyProduct("DNSq")]
|
||||
[assembly: AssemblyCopyright("Copyright © Precipice Projects 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(true)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("bbf6e069-6c4b-4597-b640-73753b5a7c5b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// 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.5.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.5.1.0")]
|
||||
[assembly: NeutralResourcesLanguage("en-NZ")]
|
||||
|
Reference in New Issue
Block a user