continuous PING application ?
-
Hi , I have here an ping application implemented as a console application. I want to turn this into a continuous ping application. Can someone give me a tip how to change this code so it runs continuously.
///////////////////////////////////////////////////////////////////////////////////////////
///
/// PingAppConsile: application testing the ping() connection to a node
///
/// Based on code form Microsoft MSDN about the ping() command
///
/// Version: 1.0: 8-JAN-17: NOS
///
///////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.NetworkInformation;
//
namespace PingAppConsole
{
class Program
{
/// /// //////////////////////////////////////////////////////////////////////////////
static void Main(string[] args)
///
/// Purpose: the main function in the application handling the ping()communication
///
/// Version: 1.0: 09-FEB-20: Adis Pipic
///
{
string host, data;
byte[] buffer;
int timeout;
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
data = "Rodham street";
buffer = Encoding.ASCII.GetBytes(data);
timeout = 120;
// Name or address of node to access
host = "www.google.no";
PingReply reply = pingSender.Send(host, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine(" Ping communication status for {0}:", host);
Console.WriteLine(" ------------------------------------------");
Console.WriteLine(" Address: {0}", reply.Address.ToString());
Console.WriteLine(" RoundTrip time (mSec): {0}", reply.RoundtripTime);
Console.WriteLine(" Time to live: {0}", reply.Options.Ttl);
Console.WriteLine(" Dont fragment: {0}", reply.Options.DontFragment);
Console.WriteLine(" Buffer size: {0}", reply.Buffer.Length); -
Hi , I have here an ping application implemented as a console application. I want to turn this into a continuous ping application. Can someone give me a tip how to change this code so it runs continuously.
///////////////////////////////////////////////////////////////////////////////////////////
///
/// PingAppConsile: application testing the ping() connection to a node
///
/// Based on code form Microsoft MSDN about the ping() command
///
/// Version: 1.0: 8-JAN-17: NOS
///
///////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.NetworkInformation;
//
namespace PingAppConsole
{
class Program
{
/// /// //////////////////////////////////////////////////////////////////////////////
static void Main(string[] args)
///
/// Purpose: the main function in the application handling the ping()communication
///
/// Version: 1.0: 09-FEB-20: Adis Pipic
///
{
string host, data;
byte[] buffer;
int timeout;
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
data = "Rodham street";
buffer = Encoding.ASCII.GetBytes(data);
timeout = 120;
// Name or address of node to access
host = "www.google.no";
PingReply reply = pingSender.Send(host, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine(" Ping communication status for {0}:", host);
Console.WriteLine(" ------------------------------------------");
Console.WriteLine(" Address: {0}", reply.Address.ToString());
Console.WriteLine(" RoundTrip time (mSec): {0}", reply.RoundtripTime);
Console.WriteLine(" Time to live: {0}", reply.Options.Ttl);
Console.WriteLine(" Dont fragment: {0}", reply.Options.DontFragment);
Console.WriteLine(" Buffer size: {0}", reply.Buffer.Length);put an infinite loop around the ping call
while ( true ) {
PingReply reply = pingSender.Send(host, timeout, buffer, options)
// ...
else
{
Console.WriteLine("Error ... ");
}
}Not sure if you could ever break out of that, though. You'd probably want to reduce that to one line of output, similar to what you get from ping from the command prompt. Oh, and you'll probably want to add a delay at the bottom of the loop so you don't flood the network with ping requests. Thread.Sleep() seems like a good option.
-
put an infinite loop around the ping call
while ( true ) {
PingReply reply = pingSender.Send(host, timeout, buffer, options)
// ...
else
{
Console.WriteLine("Error ... ");
}
}Not sure if you could ever break out of that, though. You'd probably want to reduce that to one line of output, similar to what you get from ping from the command prompt. Oh, and you'll probably want to add a delay at the bottom of the loop so you don't flood the network with ping requests. Thread.Sleep() seems like a good option.
Use a Timer. Call your routine from the Timer's Tick event. Disable / enable the Timer each time you handle the event to avoid reentrancy with short intervals.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Hi , I have here an ping application implemented as a console application. I want to turn this into a continuous ping application. Can someone give me a tip how to change this code so it runs continuously.
///////////////////////////////////////////////////////////////////////////////////////////
///
/// PingAppConsile: application testing the ping() connection to a node
///
/// Based on code form Microsoft MSDN about the ping() command
///
/// Version: 1.0: 8-JAN-17: NOS
///
///////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.NetworkInformation;
//
namespace PingAppConsole
{
class Program
{
/// /// //////////////////////////////////////////////////////////////////////////////
static void Main(string[] args)
///
/// Purpose: the main function in the application handling the ping()communication
///
/// Version: 1.0: 09-FEB-20: Adis Pipic
///
{
string host, data;
byte[] buffer;
int timeout;
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
data = "Rodham street";
buffer = Encoding.ASCII.GetBytes(data);
timeout = 120;
// Name or address of node to access
host = "www.google.no";
PingReply reply = pingSender.Send(host, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine(" Ping communication status for {0}:", host);
Console.WriteLine(" ------------------------------------------");
Console.WriteLine(" Address: {0}", reply.Address.ToString());
Console.WriteLine(" RoundTrip time (mSec): {0}", reply.RoundtripTime);
Console.WriteLine(" Time to live: {0}", reply.Options.Ttl);
Console.WriteLine(" Dont fragment: {0}", reply.Options.DontFragment);
Console.WriteLine(" Buffer size: {0}", reply.Buffer.Length);Use a Timer. Call your routine from the Timer's Tick event. Disable / enable the Timer each time you handle the event to avoid reentrancy with short intervals. Though with a timer and status reporting, I would probably use a Windows app instead of a Console app.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
put an infinite loop around the ping call
while ( true ) {
PingReply reply = pingSender.Send(host, timeout, buffer, options)
// ...
else
{
Console.WriteLine("Error ... ");
}
}Not sure if you could ever break out of that, though. You'd probably want to reduce that to one line of output, similar to what you get from ping from the command prompt. Oh, and you'll probably want to add a delay at the bottom of the loop so you don't flood the network with ping requests. Thread.Sleep() seems like a good option.
-
Thanks :) Is there a way I can check all the nodes in the network and also get the number of the nodes in my network segment?
It used to be that most nodes on a lan would respond to a broadcast ping, but most systems do not do so any longer. Many hosts also employ firewalls to block pings. And firewalls can be used to block all connections except from certain hosts, or maybe even all incoming connections. If all your nodes are connected through a simple hub, then you might be able to sniff packets on the wire and see what the source and destination nodes are. If you're using smart switches then the switch might only forward packets between the ports the nodes are attached to, so you might not see packets. So there's not any good way to do that. There's only the brute force approach, a la [Windows | Nmap Network Scanning](https://nmap.org/book/inst-windows.html). Be aware that scanning networks where you do not have permission to do so is not advised. Its not unlike someone going around the outside of your hose checking to see if any of your doors or windows are openable. There might not be any intent to create mischief, but it certainly looks like you're trying to break in!
-
It used to be that most nodes on a lan would respond to a broadcast ping, but most systems do not do so any longer. Many hosts also employ firewalls to block pings. And firewalls can be used to block all connections except from certain hosts, or maybe even all incoming connections. If all your nodes are connected through a simple hub, then you might be able to sniff packets on the wire and see what the source and destination nodes are. If you're using smart switches then the switch might only forward packets between the ports the nodes are attached to, so you might not see packets. So there's not any good way to do that. There's only the brute force approach, a la [Windows | Nmap Network Scanning](https://nmap.org/book/inst-windows.html). Be aware that scanning networks where you do not have permission to do so is not advised. Its not unlike someone going around the outside of your hose checking to see if any of your doors or windows are openable. There might not be any intent to create mischief, but it certainly looks like you're trying to break in!