Skip to content

Commit

Permalink
Changed /limit 1 and 2 to not show intro or summary messages
Browse files Browse the repository at this point in the history
Fixed /compactGraph not pinging inputted address
Added user input pause to /version
Separated out exceptions for invalid argument parameter and missing argument (was causing an OutOfBounds crash)
Changed /requests to /request (/request will still work however)
Small tweaks to /help and readme wording
  • Loading branch information
Killeroo committed Mar 30, 2019
1 parent 9e3736f commit f9e98cb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ _Future features:_
--interval [--in] number Interval between each ping (in milliseconds)
--type [--pt] number Use custom ICMP type
--code [--pc] number Use custom ICMP code value
--size [--s] number Set size of packet (overwrites packet message)
--size [--s] number Set size (in bytes) of packet (overwrites packet message)
--message [--m] message Ping packet message
--timing [--ti] timing Timing levels:
0 - Paranoid 4 - Nimble
Expand All @@ -64,7 +64,7 @@ _Future features:_
--timestamp [--ts] Display timestamp
--nocolor [--nc] No colour
--symbols [--sym] Renders replies and timeouts as ASCII symbols
--request [--r] Show request packets
--requests [--r] Show request packets
--notimeouts [--nt] Don't display timeout messages
--quiet [--q] No output (only affects normal ping)
--resolve [--res] Resolve hostname of address from DNS
Expand Down
23 changes: 16 additions & 7 deletions src/PowerPing/Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Display
public static bool ShowTimeouts { get; set; } = true;
public static bool ShowRequests { get; set; } = false;
public static bool ShowReplies { get; set; } = true;
public static bool ShowIntro { get; set; } = true;
public static bool ShowSummary { get; set; } = true;
public static bool ShowChecksum { get; set; } = false;
public static bool UseInputtedAddress { get; set; } = false;
public static bool UseResolvedAddress { get; set; } = false;
Expand Down Expand Up @@ -175,7 +177,7 @@ PowerPing [--?] | [--ex] | [--li] | [--whoami] | [--whois] [--loc] | [--fl] |
--interval [--in] number Interval between each ping (in milliseconds)
--type [--pt] number Use custom ICMP type
--code [--pc] number Use custom ICMP code value
--size [--s] number Set size of packet (overwrites packet message)
--size [--s] number Set size (in bytes) of packet (overwrites packet message)
--message [--m] message Ping packet message
--timing [--ti] timing Timing levels:
0 - Paranoid 4 - Nimble
Expand All @@ -190,14 +192,14 @@ PowerPing [--?] | [--ex] | [--li] | [--whoami] | [--whois] [--loc] | [--fl] |
--timestamp [--ts] Display timestamp
--nocolor [--nc] No colour
--symbols [--sym] Renders replies and timeouts as ASCII symbols
--request [--r] Show request packets
--requests [--r] Show request packets
--notimeouts [--nt] Don't display timeout messages
--quiet [--q] No output (only affects normal ping)
--resolve [--res] Resolve hostname of address from DNS
--inputaddr [--ia] Show input address instead of revolved IP address
--checksum [--chk] Display checksum of packet
--checksum [--chk] Display checksum of packet
--limit [--l] number Limits output to just replies(1), requests(2) or summary(3)
--decimals [--dp] number Num of decimal places to use(0 to 3)
--decimals [--dp] number Num of decimal places to use (0 to 3)
Features:
--scan [--sc] address Network scanning, specify range ""127.0.0.1-55""
Expand Down Expand Up @@ -447,14 +449,21 @@ public static void Version(bool date = false)

// Write version
Console.WriteLine(version + (date ? "[Built " + buildTime + "]" : ""));

if (!Display.NoInput) {
Helper.Pause();
}
}
/// <summary>
/// Displays help message
/// </summary>
public static void Help()
{
// Print help message
Version();
Version v = Assembly.GetExecutingAssembly().GetName().Version;
DateTime buildInfo = Assembly.GetExecutingAssembly().GetLinkerTime();
string version = Assembly.GetExecutingAssembly().GetName().Name + " v" + v.Major + "." + v.Minor + "." + v.Build + " (r" + v.Revision + ") ";
Console.WriteLine(version);
Console.WriteLine(HELP_MSG);

if (!NoInput) {
Expand Down Expand Up @@ -488,7 +497,7 @@ public static void Examples()
/// <param name="ping">Ping object</param>
public static void PingIntroMsg(PingAttributes attrs)
{
if (!Display.ShowOutput) {
if (!Display.ShowOutput || !Display.ShowIntro) {
return;
}

Expand Down Expand Up @@ -720,7 +729,7 @@ public static void ScanResults(int scanned, bool ranToEnd, List<Ping.ActiveHost>
/// <param name="ping"> </param>
public static void PingResults(PingAttributes attrs, PingResults results)
{
if (!Display.ShowOutput) {
if (!Display.ShowOutput || !Display.ShowSummary) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/PowerPing/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ namespace PowerPing
// (used in arguments parsing)
public class ArgumentFormatException : Exception { }
public class MissingArgumentException : Exception { }
public class InvalidArgumentException : Exception { }
}
25 changes: 18 additions & 7 deletions src/PowerPing/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void Main(string[] args)
{
// Local variables
int curArg = 0;
string opMode = "";
string opMode = "";
PingAttributes attributes = new PingAttributes();
attributes.Address = "";

Expand Down Expand Up @@ -269,9 +269,11 @@ static void Main(string[] args)
case "-l":
case "--l":
if (Convert.ToInt32(args[count + 1]) == 1) {
Display.ShowReplies = true;
Display.ShowRequests = false;
Display.ShowSummary = false;
Display.ShowIntro = false;
} else if (Convert.ToInt32(args[count + 1]) == 2) {
Display.ShowSummary = false;
Display.ShowIntro = false;
Display.ShowReplies = false;
Display.ShowRequests = true;
} else if (Convert.ToInt32(args[count + 1]) == 3) {
Expand Down Expand Up @@ -353,6 +355,9 @@ static void Main(string[] args)
case "/request":
case "-request":
case "--request":
case "/requests":
case "-requests":
case "--requests":
case "/r":
case "-r":
case "--r":
Expand Down Expand Up @@ -487,7 +492,7 @@ static void Main(string[] args)
if ((args[count].Contains("--") || args[count].Contains("/") || args[count].Contains("-"))
&& !opMode.Equals("scanning") // (ignore if scanning)
&& args[count].Length < 7) { // Ignore args under 7 chars (assume they are an address)
throw new ArgumentFormatException();
throw new InvalidArgumentException();
}
break;
}
Expand All @@ -505,9 +510,15 @@ static void Main(string[] args)
PowerPing.Display.Message("Use \"PowerPing /help\" or \"PowerPing /?\" for help.");
Helper.Pause();
return;
} catch (InvalidArgumentException) {
PowerPing.Display.Error("Invalid argument", false, false, false);
PowerPing.Display.Message(" @ \"PowerPing >>>" + args[curArg] + "<<<\"", ConsoleColor.Red);
PowerPing.Display.Message("Use \"PowerPing /help\" or \"PowerPing /?\" for help.");
Helper.Pause();
return;
} catch (ArgumentFormatException) {
PowerPing.Display.Error("Invalid argument or incorrect parameter for [" + args[curArg] + "]", false, false, false);
PowerPing.Display.Message(" @ \"PowerPing " + args[curArg] + " >>>" + args[curArg+1] + "<<<\"", ConsoleColor.Red);
PowerPing.Display.Error("Incorrect parameter for [" + args[curArg] + "]", false, false, false);
PowerPing.Display.Message(" @ \"PowerPing " + args[curArg] + " >>>" + args[curArg + 1] + "<<<\"", ConsoleColor.Red);
PowerPing.Display.Message("Use \"PowerPing /help\" or \"PowerPing /?\" for help.");
Helper.Pause();
return;
Expand All @@ -521,7 +532,7 @@ static void Main(string[] args)

// Find address
if (opMode.Equals("") || opMode.Equals("flooding") || opMode.Equals("graphing")
|| opMode.Equals("compactGraph") || opMode.Equals("location") || opMode.Equals("whois")) {
|| opMode.Equals("compactgraph") || opMode.Equals("location") || opMode.Equals("whois")) {

if (Uri.CheckHostName(args.First()) == UriHostNameType.Unknown
&& Uri.CheckHostName(args.Last()) == UriHostNameType.Unknown) {
Expand Down

0 comments on commit f9e98cb

Please sign in to comment.