Continue Pinging

  • Thread starter Thread starter Theepan123
  • Start date Start date
T

Theepan123

Guest
<g class="gr_ gr_41 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" data-gr-id="41" id="41">Hi</g> I have Project call List of IP addresses need to pinging and then reply status that those <g class="gr_ gr_40 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="40" id="40">ip</g> address using the timer.

<g class="gr_ gr_42 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="42" id="42">i</g> am done with the project but the issue is when the run long time for example 12 hours Object reference error



Here the code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Net.NetworkInformation;
using System.Collections.Specialized;
using System.Configuration;
using Qlib;
using System.IO;
using System.Timers;
using System.Windows.Forms;
using System.Threading;

namespace PingAddress
{

public partial class <g class="gr_ gr_40 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" data-gr-id="40" id="40">Form1 :</g> Form
{
string Ip_address_value;
PingReply rep_ipaddress;
System.Timers.Timer time;
Ping pingasync;
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public Form1()
{
key.SetValue("IP Address ping ",Application.ExecutablePath.ToString());
InitializeComponent();
Qlib.Logger.SolutionName = "Ping Information";
Qlib.Logger.SubprojectName = "Ping Qlog";
try
{
if (ConfigurationManager.AppSettings["log"] == "on")
{
Logger.EnableLogging = true;
}
Logger.Log("logger is Started");
}
catch (Exception e)
{
Logger.Log("Qlib Exception:" + e.Message);
}

}
private void Form1_Load(object sender, EventArgs e)
{

time = new System.Timers.Timer();
time.Elapsed += Time_Elapsed;
time.Interval = 5000;
time.Enabled = true;
time.AutoReset = true;

this.Hide();
}

private void Time_Elapsed(object sender, ElapsedEventArgs e)
{
time.Stop();
//PingIp(Ip_address_value);
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Qlib.Logger.Log("config:" + config);
ConfigurationSectionGroup fileCheckersGroup = config.SectionGroups["FileCheckers"];
Qlib.Logger.Log("fileCheckersGroup:" + fileCheckersGroup);
foreach (ConfigurationSection section in fileCheckersGroup.Sections)
{
NameValueCollection sectionSettings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
Qlib.Logger.Log("sectionSettings:" + sectionSettings);
Ip_address_value = sectionSettings["IPAddress"];
Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
//PingIp(Ip_address_value);
Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
Ping myPing = new Ping();
PingIp(Ip_address_value);
System.Threading.Thread.Sleep(4000);
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.Text = rep_ipaddress.Address.ToString();
Qlib.Logger.Log("IP address:-" + rep_ipaddress);
notifyIcon1.Visible = true;
//Qlib.Logger.Log("notifyIcon1.Visible");
notifyIcon1.BalloonTipTitle = "Welcome IpStatus:-Your Ip Is:-" + rep_ipaddress.Address;
Qlib.Logger.Log("Ip Address:" + rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Reply From { 0}:bytes ={ 3} ,time = { 1},TTL ={ 2}" + rep_ipaddress.Address.ToString() + " " + rep_ipaddress.RoundtripTime + " " + rep_ipaddress.Options.Ttl + "" + rep_ipaddress.Buffer.Length;
//Qlib.Logger.Log("BalloonTipText");
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("Success");
Qlib.Logger.Log("------Success END----");
System.Threading.Thread.Sleep(2000);

}
time.Start();
}


private void PingIp(string <g class="gr_ gr_41 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="41" id="41">ip</g>)
{
PingReply rep_ipaddress;
try
{
pingasync = new Ping();
rep_ipaddress = pingasync.Send(ip, 3000);
Qlib.Logger.Log("IP address:-" + rep_ipaddress);
if (rep_ipaddress != null)
{
Qlib.Logger.Log("IP address:-" + ip);
Qlib.Logger.Log("rep_ipaddress:-" + rep_ipaddress);
var pingSender = new Ping();
string data = Encoding.ASCII.GetString(rep_ipaddress.Buffer);
byte[] buffer = Encoding.ASCII.GetBytes(data);
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.Text = rep_ipaddress.Address.ToString();
Qlib.Logger.Log("IP Address:-" + rep_ipaddress);
notifyIcon1.Visible = true;
notifyIcon1.BalloonTipTitle = "Pinging:-" + rep_ipaddress.Address + " " + "with 32 bytes of data";
Qlib.Logger.Log("Pinging:-" + rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Reply From {0} :" + "" + rep_ipaddress.Address.ToString() + ":" + "bytes ={2}:" + rep_ipaddress.Buffer.Length + "Time = {2}" + "" + rep_ipaddress.RoundtripTime + "ms" + "" + "TTL ={3}" + "" + rep_ipaddress.Options.Ttl;
Qlib.Logger.Log("Reply From :-" + rep_ipaddress.Address);
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("------Success END----");
}
else
{
Qlib.Logger.Log("Ip address is null");
}
}
catch(Exception ex)
{
Qlib.Logger.Log("------Exception----:-"+ex.Message); Exception please check exception below
Qlib.Logger.Log(ex.Source);
Qlib.Logger.Log(ex.StackTrace);
Qlib.Logger.Log(ex.Message);
notifyIcon1.Icon = SystemIcons.Application;
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
//Qlib.Logger.Log(" notifyIcon1.Visible");
notifyIcon1.Visible = true;
//Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "IpStatus TimeOut:-" + rep_ipaddress.Address;
// Qlib.Logger.Log("IpStatus TimeOut:-"+rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Status Error:-" + "Please Check Your Ip Address it seems to be this address invalid";
// Qlib.Logger.Log("notifyIcon1.Visible");
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("------Exception END----");
// PingIp(Ip_address_value);
}
}

}
}

Exception

IP address:-System.Net.NetworkInformation.PingReply
25864 [8/24/2018 4:00:26 PM] : IP address:-192.168.48.151
25865 [8/24/2018 4:00:26 PM] : ------Exception----
25866 [8/24/2018 4:00:26 PM] : PingAddress
25867 [8/24/2018 4:00:26 PM] : at PingAddress.Form1.PingIp(String ip)
25868 [8/24/2018 4:00:26 PM] : Object reference not set to an instance of an object.






<g class="gr_ gr_30 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="30" id="30">kandeepan</g>

Continue reading...
 
Back
Top