Added solution files

This commit is contained in:
Brychan Dempsey 2021-10-06 14:13:49 +13:00
parent 62e867a101
commit 8834ecb17d
4 changed files with 274 additions and 0 deletions

22
PingM.sln Normal file
View 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}") = "PingM", "PingM\PingM.csproj", "{98EFB8A7-4BF8-4FA8-82E7-DCD622318D20}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98EFB8A7-4BF8-4FA8-82E7-DCD622318D20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98EFB8A7-4BF8-4FA8-82E7-DCD622318D20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98EFB8A7-4BF8-4FA8-82E7-DCD622318D20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98EFB8A7-4BF8-4FA8-82E7-DCD622318D20}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

54
PingM/PingM.csproj Normal file
View File

@ -0,0 +1,54 @@
<?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>{98EFB8A7-4BF8-4FA8-82E7-DCD622318D20}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PingM</RootNamespace>
<AssemblyName>PingM</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<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>
<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>

162
PingM/Program.cs Normal file
View File

@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
namespace PingM
{
class Program
{
static void Main(string[] args)
{
// make sure all args are lowercase
string[] commandArgs = args;
for(int i = 0; i < args.Length; i++)
{
commandArgs[i] = args[i].ToLower();
}
int hostIndex = Array.IndexOf(commandArgs, "-h");
string[] ipMinMax;
if (args == null || args.Count() == 0 || args[0] == "" || commandArgs[0] == "/?" || commandArgs[0] == "help")
{
Console.WriteLine("");
Console.WriteLine("PingM provides command-line ping packets that are targeted at multiple Ip Addresses");
Console.WriteLine("Usage:");
Console.WriteLine("PingM [/?] [Ip Address] [Ip Address]");
Console.WriteLine("");
Console.WriteLine("Options:");
Console.WriteLine("\t /? or help | This page");
Console.WriteLine("\t [IpAddress] [IpAddress] | Pings the provided range of Ip\'s");
Console.WriteLine("\t -h | Display returned packets only");
Console.WriteLine("");
Console.WriteLine("Note that large ranges of Ip addresses can take a long time");
}
else
{
Console.WriteLine("A range has been supplied, verifying Ip Addresses...");
if (Array.IndexOf(args, '-') == -1)
{
ipMinMax = args;
}
else
{
ipMinMax = args[0].Split('-');
}
IPAddress firstIp;
IPAddress secondIp;
IPAddress.TryParse(ipMinMax[0], out firstIp);
IPAddress.TryParse(ipMinMax[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]);
long rawNumber = powerOf(seg1diff, 3) + powerOf(seg2diff, 2) + powerOf(seg3diff, 1) + seg4diff;
Console.WriteLine("Total number of addressess between {0} and {1}: {2}", firstIp, secondIp, rawNumber);
Ping controlPing = new Ping();
PingOptions options = new PingOptions();
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
for (int i = 0; i < rawNumber; i++)
{
// Dns Lookup Logic
string ipCheck = seg1[0] + "." + seg2[0] + "." + seg3[0] + "." + seg4[0];
try
{
PingReply replyData = controlPing.Send(ipCheck, timeout, buffer, options);
if (hostIndex != -1)
{
if(replyData.Status == IPStatus.Success)
{
Console.WriteLine("Pinging {0} was {1}", ipCheck, replyData.Status);
}
}
else
{
Console.WriteLine("Pinging {0} was {1}", ipCheck, replyData.Status);
}
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
seg4[0]++;
continue;
}
// 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");
}
}
}
}
}
}
Console.ReadLine();
}
private static long powerOf(int inDiff, int totalSuffixBytes)
{
long returnTotal;
double tempTotal;
double tempPower;
tempPower = Math.Log(inDiff, 2);
tempTotal = Math.Pow(2, (Convert.ToDouble(totalSuffixBytes) * 8) + tempPower);
returnTotal = Convert.ToInt64(tempTotal);
return returnTotal;
}
}
}

View File

@ -0,0 +1,36 @@
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("PingM")]
[assembly: AssemblyDescription("Ping Multiple IP Addresses")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Precipice Projects")]
[assembly: AssemblyProduct("PingM")]
[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(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("98efb8a7-4bf8-4fa8-82e7-dcd622318d20")]
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]