Skip to content

Commit

Permalink
Ver 1.2.0 Update
Browse files Browse the repository at this point in the history
This update includes:
Logcat now will display using IP when pinging a host name;
Every time creating a new ping it will only query DNS one time.
  • Loading branch information
KobeArthurScofield authored Sep 10, 2019
1 parent 5048433 commit 10ece8e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Auto Ping Csharp/Auto Ping Csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<ProductName>Auto Ping Worker</ProductName>
<PublisherName>Kobe Arthur Scofield</PublisherName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>79</ApplicationRevision>
<ApplicationVersion>1.1.3.%2a</ApplicationVersion>
<ApplicationRevision>95</ApplicationRevision>
<ApplicationVersion>1.2.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down
99 changes: 73 additions & 26 deletions Auto Ping Csharp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.NetworkInformation;
using System.Net;
using System.Threading;
using System.Collections;

Expand All @@ -24,12 +25,13 @@ public class DataSct
{
public struct PingParam
{
public string destination;
public Int32 buffersize;
public bool dflag;
public Int32 ttl;
public Int32 timeout;
public Int32 interval;
public string destination;
public IPAddress destinationaddress;
public Int32 buffersize;
public bool dflag;
public Int32 ttl;
public Int32 timeout;
public Int32 interval;
};
}

Expand Down Expand Up @@ -147,36 +149,53 @@ public void LocalTest(object sender)
public void PingerLauncher(object pingparam)
{
StatusUpdater statusUpdater = StdUpd;
DataSct.PingParam pingparamdata = (DataSct.PingParam)pingparam;
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Important, "Ping worker launcher started.");
lock (totalaccesslock)
{
statisticpackcount = default_timewindow / pingparamdata.interval;
sentpackcount = 0;
}
lock (statisticaccesslock)
DataSct.PingParam pingparamdata = (DataSct.PingParam)pingparam;
bool pingallowed;
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Important, "Fetching IP...");
if ((pingparamdata.destinationaddress = FetchHostAddress(pingparamdata.destination)) != null)
pingallowed = true;
else
pingallowed = false;
if (pingallowed)
{
successpackcount = 0;
failedpackcount = 0;
totalrtt = 0;
RTT.Clear();
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Destination check OK.");
lock (totalaccesslock)
{
statisticpackcount = default_timewindow / pingparamdata.interval;
sentpackcount = 0;
}
lock (statisticaccesslock)
{
successpackcount = 0;
failedpackcount = 0;
totalrtt = 0;
RTT.Clear();
}
Timer timer = new Timer(Pinger, pingparamdata, 0, pingparamdata.interval);
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Ping worker lighter started.");
controlon.WaitOne();
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker launcher dying.");
timer.Dispose(controlon);
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker lighter broken.");
}
Timer timer = new Timer(Pinger, pingparam, 0, pingparamdata.interval);
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Information, "Ping worker lighter started.");
controlon.WaitOne();
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker launcher dying.");
timer.Dispose(controlon);
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, "Ping worker lighter broken.");
else
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, "Network error or wrong destination, ping worker launcher dying.");
}

public void Pinger(object pingparam)
{
DataSct.PingParam pingparamdata = (DataSct.PingParam)pingparam;
Ping pingwork = new Ping();
StatusUpdater statusUpdater = StdUpd;
string destinationdisplay;
if (string.Compare(pingparamdata.destination, pingparamdata.destinationaddress.ToString()) != 0)
destinationdisplay = pingparamdata.destination + " (" + pingparamdata.destinationaddress + ")";
else
destinationdisplay = pingparamdata.destination;
try
{
PingReply pingReply = pingwork.Send(pingparamdata.destination, pingparamdata.timeout, new byte[pingparamdata.buffersize], new PingOptions(pingparamdata.ttl, pingparamdata.dflag));
PingReply pingReply = pingwork.Send(pingparamdata.destinationaddress, pingparamdata.timeout, new byte[pingparamdata.buffersize], new PingOptions(pingparamdata.ttl, pingparamdata.dflag));
lock (totalaccesslock)
{
if (sentpackcount < statisticpackcount)
Expand All @@ -187,12 +206,12 @@ public void Pinger(object pingparam)
PackCouter(true, pingReply.RoundtripTime);
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.CurrentPing, pingReply.RoundtripTime.ToString("0ms"));
if (((pingReply.RoundtripTime > pingparamdata.interval) && (pingparamdata.interval > 500)) || (pingReply.RoundtripTime >= 1000))
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, pingparamdata.destination + " ICMP reply latecy too long: " + pingReply.RoundtripTime.ToString("0ms"));
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Warning, destinationdisplay + " ICMP reply latecy too long: " + pingReply.RoundtripTime.ToString("0ms"));
}
else
{
PackCouter(false, null);
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, pingparamdata.destination + " " + ICMPErrorAnalasys(pingReply.Status));
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.Error, destinationdisplay + " " + ICMPErrorAnalasys(pingReply.Status));
Dispatcher.Invoke(statusUpdater, ValueSign.StatusSign.CurrentPing, "Failed");
}
}
Expand Down Expand Up @@ -278,6 +297,34 @@ public void NetworkState(object sender)
}
}

public IPAddress FetchHostAddress(string sourceinput)
{
IPAddress[] addresspending;
IPAddress addressreturn = null;
try
{
addresspending = Dns.GetHostAddresses(sourceinput);
if (addresspending[0] != null)
for (Int32 i = 0; i < addresspending.Length; i++)
{
Ping ping = new Ping();
PingReply pingReply = ping.Send(addresspending[i], 20);
if (pingReply.Status != IPStatus.BadDestination)
{
addressreturn = addresspending[i];
break;
}
else if (i == (addresspending.Length - 1))
addressreturn = addresspending[0];
}
}
catch (Exception exception)
{
ExceptionLogcat(exception);
}
return addressreturn;
}

public void StdUpd(ValueSign.StatusSign field, string data)
{
DateTime dateTimeUTC = DateTime.UtcNow;
Expand Down
4 changes: 2 additions & 2 deletions Auto Ping Csharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// 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.1.3.79")]
[assembly: AssemblyFileVersion("1.1.3.5")]
[assembly: AssemblyVersion("1.2.0.95")]
[assembly: AssemblyFileVersion("1.2.0.6")]
[assembly: NeutralResourcesLanguage("en-US")]

0 comments on commit 10ece8e

Please sign in to comment.