Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 DotRas;
- using Microsoft.Win32;
- using System.Net;
- using System.IO;
- using System.Net.NetworkInformation;
- using System.Net.Sockets;
- using System.Diagnostics;
- namespace pppoe_dialer___zaib_last
- {
- public partial class Form1 : Form
- {
- public class Globals
- {
- public static string PPPNAME = "Internet-Dialer";
- }
- private Timer _timer;
- private DateTime _startTime = DateTime.MinValue;
- private TimeSpan _currentElapsedTime = TimeSpan.Zero;
- private TimeSpan _totalElapsedTime = TimeSpan.Zero;
- private bool _timerRunning = false;
- DateTime _started = DateTime.UtcNow;
- DateTime startTime = new DateTime();
- private NetworkInterface[] nicArr;
- int lanInterval = 2; //3 sec
- int netInterval = 10; //10 sec
- private Timer timer;
- private const double timerUpdate = 1000;
- //private bool willClose;
- private bool connected;
- private RasHandle handle = null;
- private RasHandle Rashandler = null;
- private RasConnection connection = null;
- //DateTime startTime = new DateTime();
- public Form1()
- {
- InitializeComponent();
- // Set up a timer and fire the Tick event once per second (1000 ms)
- //textBox2.PasswordChar='*';
- InitializeNetworkInterface();
- InitializeTimer();
- _timer = new Timer();
- _timer.Interval = 1000;
- _timer.Tick += new EventHandler(_timer_Tick);
- Timer t = new Timer();
- t.Interval = 1000; //1 sec
- t.Tick += new EventHandler(t_Tick);
- t.Start();
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- {
- startelptimer();
- }
- if (conn != null)
- {
- var local = NetworkInterface.GetAllNetworkInterfaces().Where(i => i.Name == Globals.PPPNAME).FirstOrDefault();
- var stringAddress = local.GetIPProperties().UnicastAddresses[0].Address.ToString();
- var ipAddress1 = IPAddress.Parse(stringAddress);
- pppip.Text = "Your Internet IP is : " + ipAddress1;
- notifyIcon1.Icon = Resource1.icon_online;
- this.pictureBox2.Image = Resource1.net_conn_image_1;
- }
- else
- {
- this.pictureBox2.Image = Resource1.net_disconnected_image_2;
- sl2.Text = "Not Connected";
- //this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Dialer already connected!"));
- }
- }
- void _timer_Tick(object sender, EventArgs e)
- {
- // We do this to chop off any stray milliseconds resulting from
- // the Timer's inherent inaccuracy, with the bonus that the
- // TimeSpan.ToString() method will now show correct HH:MM:SS format
- var timeSinceStartTime = DateTime.Now - _startTime;
- timeSinceStartTime = new TimeSpan(timeSinceStartTime.Hours,
- timeSinceStartTime.Minutes,
- timeSinceStartTime.Seconds);
- // The current elapsed time is the time since the start button was
- // clicked, plus the total time elapsed since the last reset
- _currentElapsedTime = timeSinceStartTime + _totalElapsedTime;
- // These are just two Label controls which display the current
- // elapsed time and total elapsed time
- //sl.Text = _currentElapsedTime.ToString();
- sl2.Text = timeSinceStartTime.ToString();
- }
- private void timerdialer_Tick(object sender, EventArgs e)
- {
- var timeSinceStartTime = DateTime.Now - _startTime;
- timeSinceStartTime = new TimeSpan(timeSinceStartTime.Hours,
- timeSinceStartTime.Minutes,
- timeSinceStartTime.Seconds);
- // The current elapsed time is the time since the start button was
- // clicked, plus the total time elapsed since the last reset
- _currentElapsedTime = timeSinceStartTime + _totalElapsedTime;
- // These are just two Label controls which display the current
- // elapsed time and total elapsed time
- //sl.Text = _currentElapsedTime.ToString();
- sl2.Text = timeSinceStartTime.ToString();
- }
- private void timerStart_Click(object sender, EventArgs e)
- {
- // If the timer isn't already running
- // Set the start time to Now
- _startTime = DateTime.Now;
- // Store the total elapsed time so far
- //_totalElapsedTime = _currentElapsedTime;
- _timer.Start();
- _timerRunning = true;
- }
- private void InitializeNetworkInterface()
- {
- // Grab all local interfaces to this computer
- nicArr = NetworkInterface.GetAllNetworkInterfaces();
- // Add each interface name to the combo box
- for (int i = 0; i < nicArr.Length; i++)
- cmbInterface.Items.Add(nicArr[i].Name);
- // Change the initial selection to the first interface
- cmbInterface.SelectedIndex = 0;
- }
- private void InitializeTimer()
- {
- timer = new Timer();
- timer.Interval = (int)timerUpdate;
- timer.Tick += new EventHandler(timer_Tick);
- timer.Start();
- }
- void t_Tick(object sender, EventArgs e)
- {
- lanInterval--;
- netInterval--;
- if (lanInterval == 0)
- {
- checkpppstatus();
- lanInterval = 2; //reset to base value
- }
- if (netInterval == 0)
- {
- checknetstatus();
- netInterval = 10; //reset to base value
- }
- }
- protected void checkpppstatus()
- {
- this.Invoke((MethodInvoker)delegate
- {
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- {
- connstatus.Text = "Dialer Status: Connected!";
- connstatus.ForeColor = System.Drawing.Color.Green;
- }
- else
- {
- connstatus.Text = "Dialer Status: Disconnected!";
- connstatus.ForeColor = System.Drawing.Color.Red;
- pppip.Text = "Your Internet IP is : Not Connected!";
- sl2.Text = "Not Connected";
- }
- });
- }
- protected void checknetstatus()
- {
- if (IsOnline(textBox1.Text) == true)
- {
- internetStatus.ForeColor = System.Drawing.Color.Green;
- string Status = "Internet Stauts: UP";
- internetStatus.Text = Status;
- }
- else
- {
- internetStatus.ForeColor = System.Drawing.Color.Red;
- string Status = "Internet Stauts: DOWN";
- internetStatus.Text = Status;
- }
- }
- protected void Displaynotify()
- {
- try
- {
- notifyIcon1.BalloonTipTitle = "You have successfully connected to the Internet ...";
- notifyIcon1.BalloonTipText = "Internet Connected ...";
- notifyIcon1.Visible = true;
- notifyIcon1.ShowBalloonTip(5000);
- }
- catch (Exception ex)
- {
- }
- }
- protected void stopelptimer()
- {
- // If the timer isn't already running
- // Set the start time to Now
- _startTime = DateTime.Now;
- // Store the total elapsed time so far
- //_totalElapsedTime = _currentElapsedTime;
- _timer.Stop();
- _timerRunning = false;
- TimeSpan _currentElapsedTime = TimeSpan.Zero;
- TimeSpan _totalElapsedTime = TimeSpan.Zero;
- _totalElapsedTime = _currentElapsedTime;
- _timer.Stop();
- _timerRunning = false;
- }
- protected void startelptimer()
- {
- // If the timer isn't already running
- // Set the start time to Now
- _startTime = DateTime.Now;
- // Store the total elapsed time so far
- //_totalElapsedTime = DateTime.Now;
- _timer.Start();
- _timerRunning = true;
- }
- protected void Displaynotifyfordisconnect()
- {
- try
- {
- notifyIcon1.BalloonTipTitle = "My PPPoE Dialer DISCONNECTED !!!";
- notifyIcon1.BalloonTipText = "Internet Disconnected !!!";
- notifyIcon1.Visible = true;
- notifyIcon1.ShowBalloonTip(5000);
- // MessageBox.Show("DC");
- {
- this.Invoke((MethodInvoker)delegate
- {
- this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "\r\nDialer Disconnected!"));
- });
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void saveCredential(string username, string password, bool remember, bool auto)
- {
- RegistryKey hkcu = Registry.CurrentUser;
- RegistryKey software = hkcu.OpenSubKey("Software", true);
- RegistryKey zaib = software.CreateSubKey("zaib");
- zaib.SetValue("username", username, RegistryValueKind.String);
- zaib.SetValue("password", password, RegistryValueKind.String);
- zaib.Close();
- }
- private void readCredential()
- {
- RegistryKey hkcu = Registry.CurrentUser;
- RegistryKey software = hkcu.OpenSubKey("Software", true);
- RegistryKey zaib = software.CreateSubKey("zaib");
- try
- {
- textBox1.Text = (string)zaib.GetValue("username", "");
- textBox2.Text = (string)zaib.GetValue("password", "");
- //checkRemember.Checked = ((int)zaib.GetValue("remember") == 1);
- //checkAuto.Checked = ((int)zaib.GetValue("auto") == 1);
- }
- catch (Exception ex)
- {
- // never saved
- }
- zaib.Close();
- }
- private void Form1_Move_1(object sender, EventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- this.Hide();
- notifyIcon1.ShowBalloonTip(2000, "My PPPoE Dialer", "The App has be moved to the tray.", ToolTipIcon.Info);
- checkpppstatus();
- //timer.Dispose();
- //this.Dispose();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string path;
- path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
- using (RasPhoneBook pbk = new RasPhoneBook())
- {
- pbk.Open(path);
- RasEntry entry = RasEntry.CreateBroadbandEntry(Globals.PPPNAME, RasDevice.GetDeviceByName("PPPOE", RasDeviceType.PPPoE, false));
- // Configure any options for your entry here via entry.Options
- entry.RedialCount = 99;
- // Finally Add the PPPOE Dialer in the network connection , hurrahhhh , zaib
- // If Preiovus Entry found, delete, and reacreate
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- {
- MessageBox.Show("Same Dialer Already Connected! First Disconnect it to re-create new.");
- return;
- }
- pbk.Entries.Clear();
- rasDialer1.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
- rasDialer1.AllowUseStoredCredentials = true;
- pbk.Entries.Add(entry);
- // If Dialer Create, show successfull message.
- MessageBox.Show("Internet Dialer created Successfully.");
- saveCredential("test", "test", true, true);
- ///// SHORTCUT BEGINE
- string destDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- string destFileName = @"Connect To My Internet Dialer.lnk";
- // Create .lnk file
- string path2 = System.IO.Path.Combine(destDir, destFileName);
- FileStream fs = File.Create(path2);
- fs.Close();
- // Instantiate a ShellLinkObject that references the .lnk we created
- Shell32.Shell shell = new Shell32.Shell();
- Shell32.Folder shellFolder = shell.NameSpace(destDir);
- Shell32.FolderItem shellFolderItem = shellFolder.Items().Item(destFileName);
- Shell32.ShellLinkObject shellLinkObject = (Shell32.ShellLinkObject)shellFolderItem.GetLink;
- // Set .lnk properties
- shellLinkObject.Arguments = "-d pppoe2";
- shellLinkObject.Description = Globals.PPPNAME;
- shellLinkObject.Path = @"%windir%\System32\rasphone.exe";
- shellLinkObject.WorkingDirectory = "%windir%";
- shellLinkObject.Save(path2);
- //// SHORTCUT END
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_Click(object sender, EventArgs e)
- {
- // textBox1.Clear();
- }
- private void Button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void textBox2_Click(object sender, EventArgs e)
- {
- //textBox2.Clear();
- }
- private void label1_Click_1(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("https://aacable.wordpress.com");
- }
- private void pictureBox2_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("https://aacable.wordpress.com");
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- RasHandle handle = null;
- using (RasDialer dialer = new RasDialer())
- {
- dialer.StateChanged += new EventHandler<StateChangedEventArgs>(rasDialer1_StateChanged);
- dialer.EntryName = (Globals.PPPNAME);
- {
- // this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "OK ...", "{0}\r\n\r\n"));
- };
- //this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Connection in progress ...", "{0}\r\n\r\n"));
- dialer.StateChanged += new EventHandler<StateChangedEventArgs>(rasDialer1_StateChanged);
- dialer.EntryName = (Globals.PPPNAME);
- string username = textBox1.Text;
- string passwd = textBox2.Text;
- dialer.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
- dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
- dialer.Timeout = 1000;
- dialer.AllowUseStoredCredentials = true;
- dialer.EntryName = (Globals.PPPNAME);
- rasDialer1.EntryName = (Globals.PPPNAME);
- rasDialer1.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
- rasDialer1.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
- // If username or password window is empty , post error
- if (string.IsNullOrWhiteSpace(textBox1.Text))
- {
- this.StatusTextBox.AppendText(string.Format("{0}\r\n\r", "You must enter username/password in order to dial", "{0}\r\n"));
- //MessageBox.Show("Enter username.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- //
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- {
- this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Dialer already connected!"));
- //MessageBox.Show("Dialer - Already connected!");
- }
- else
- handle = rasDialer1.DialAsync();
- }
- }
- private void StatusTextBox_TextChanged(object sender, EventArgs e)
- {
- // MessageBox.Show("abc1");
- }
- private void rasDialer1_StateChanged(object sender, StateChangedEventArgs e)
- {
- this.Invoke((MethodInvoker)delegate
- {
- this.StatusTextBox.AppendText(string.Format(e.State.ToString() + "\r\n"));
- checkpppstatus();
- });
- }
- private void rasDialer1_DialCompleted(object sender, DialCompletedEventArgs e)
- {
- {
- if (e.Cancelled)
- {
- MessageBox.Show("Cancelled");
- }
- else if (e.TimedOut)
- {
- MessageBox.Show("Time out");
- }
- else if (e.Error != null)
- {
- MessageBox.Show(e.Error.ToString(), "Error");
- }
- else if (e.Connected)
- {
- //label9.Text = 0 + "";
- //timerdialer.Start();
- //MessageBox.Show("Connection successful zaib!");
- //this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Connected!"));
- //string newText = "abc";
- var conn = RasConnection.GetActiveConnections().Where(c => c.EntryName == Globals.PPPNAME).FirstOrDefault();
- RasIPInfo ipAddresses = (RasIPInfo)conn.GetProjectionInfo(RasProjectionType.IP);
- this.StatusTextBox.AppendText(string.Format("{0}\r\n", "Your internet ip is", ipAddresses.IPAddress.ToString()));
- this.StatusTextBox.AppendText(string.Format("{0} ", ipAddresses.IPAddress.ToString()));
- saveCredential("test", "test", true, true);
- var local = NetworkInterface.GetAllNetworkInterfaces().Where(i => i.Name == Globals.PPPNAME).FirstOrDefault();
- var stringAddress = local.GetIPProperties().UnicastAddresses[0].Address.ToString();
- var ipAddress1 = IPAddress.Parse(stringAddress);
- pppip.Text = "Your Internet IP is : " + ipAddress1;
- //gwLabel.Text = "Gateway is : " + ";
- ShowInTaskbar = true;
- this.Hide();
- InitializeNetworkInterface();
- //Displaynotify();
- UpdateNetworkInterface();
- stopelptimer();
- startelptimer();
- }
- }
- }
- private void dcButton_Click(object sender, EventArgs e)
- {
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- {
- //InitializeNetworkInterface();
- conn.HangUp();
- //MessageBox.Show("Disconnect on User Request");
- this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "\r\nDisconnected on user request !"));
- //timer.Dispose();
- //lblSpeed.Text = "-";
- lblInterfaceType.Text = "-";
- //lblSpeed.Text = "-";
- //lblBytesReceived.Text = "-";
- //lblBytesSent.Text = "-";
- lblUpload.Text = "-";
- lblDownload.Text = "-";
- connstatus.ForeColor = Color.Red;
- checkpppstatus();
- this.Hide();
- Displaynotifyfordisconnect();
- }
- else
- MessageBox.Show("Dialer is not Active !", Globals.PPPNAME);
- }
- private void rasDialer1_Error(object sender, System.IO.ErrorEventArgs e)
- {
- //this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "\r\n AUTO DC DONT KNOW !"));
- MessageBox.Show("UNKOWN!!!!!!!!!!!!");
- }
- private void Form1_Resize(object sender, EventArgs e)
- {
- notifyIcon1.Text = "My Internet Dialer";
- }
- private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- this.Show();
- this.WindowState = FormWindowState.Normal;
- }
- private void notifyIcon1_MouseDoubleClick_1(object sender, MouseEventArgs e)
- {
- Show();
- WindowState = FormWindowState.Normal;
- }
- private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)
- {
- notifyIcon1.Text = "My Internet Dialer";
- }
- private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
- {
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- }
- private void notifyIcon1_BalloonTipShown(object sender, EventArgs e)
- {
- }
- private void Form1_Load_1(object sender, EventArgs e)
- {
- timer4dt.Start();
- datelabel.Text = DateTime.Now.ToLongDateString();
- timelabel.Text = DateTime.Now.ToLongTimeString();
- readCredential();
- checkpppstatus();
- Timer MyTimer = new Timer();
- MyTimer.Interval = 5000;
- MyTimer.Tick += new EventHandler(MyTimer_Tick);
- MyTimer.Start();
- Timer MyTimer10 = new Timer();
- MyTimer10.Interval = 5000;
- MyTimer10.Tick += new EventHandler(MyTimer_Tick);
- MyTimer10.Start();
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Dialer already connected!"));
- }
- private void MyTimer_Tick(object sender, EventArgs e)
- {
- //checkpppstatus();
- }
- private void MyTimer10_Tick(object sender, EventArgs e)
- {
- // checknetstatus();
- }
- private void contextMenuStrip1_DoubleClick(object sender, EventArgs e)
- {
- this.Show();
- }
- private void showToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Show();
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void notifyIcon1_Click(object sender, EventArgs e)
- {
- this.Show();
- WindowState = FormWindowState.Normal;
- }
- private void label3_Click(object sender, EventArgs e)
- {
- }
- private void connstatus_Click(object sender, EventArgs e)
- {
- }
- private void connstatus_Click_1(object sender, EventArgs e)
- {
- }
- private void rasDialDialog1_Error(object sender, RasErrorEventArgs e)
- {
- }
- private void rasConnectionWatcher1_Disconnected(object sender, RasConnectionEventArgs e)
- {
- checkpppstatus();
- notifyIcon1.Icon = Resource1.icon_standby;
- this.pictureBox2.Image = Resource1.net_disconnected_image_2;
- Displaynotifyfordisconnect();
- //i = +0;
- stopelptimer();
- }
- private void rasConnectionWatcher1_Connected(object sender, RasConnectionEventArgs e)
- {
- UpdateNetworkInterface();
- Displaynotify();
- //startelptimer();
- notifyIcon1.Icon = Resource1.icon_online;
- this.pictureBox2.Image = Resource1.net_conn_image_1;
- }
- private void rasConnectionWatcher1_Error(object sender, ErrorEventArgs e)
- {
- MessageBox.Show("ERR");
- }
- private void rasPhoneBookDialog1_ChangedEntry(object sender, RasPhoneBookDialogEventArgs e)
- {
- MessageBox.Show("ENTRY CHANGED");
- }
- // Tafreeh start
- public bool IsOnline(string website)
- {
- Ping x = new Ping();
- PingReply reply = x.Send(IPAddress.Parse("8.8.8.8")); //enter ip of the machine
- if (reply.Status == IPStatus.Success) // here we check for the reply status if it is success it means the host is reachable
- {
- return true;
- // status.Text = "Available. And Round Trip Time of the packet is:" + reply.RoundtripTime.ToString();
- }
- else //if host is not reachable.
- return false;
- // status.Text = "Not available";
- }
- //}
- private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- System.Diagnostics.Process.Start("https://aacable.wordpress.com");
- }
- // // INTERFACE DOWNLOAD UPLOAD SETTINGA
- private void UpdateNetworkInterface()
- {
- this.Invoke((MethodInvoker)delegate
- {
- NetworkInterface nic = nicArr[cmbInterface.SelectedIndex];
- IPv4InterfaceStatistics interfaceStats = nic.GetIPv4Statistics();
- long lngBytesSent = 0;
- long lngBtyesReceived = 0;
- int bytesSentSpeed = (int)(interfaceStats.BytesSent - lngBytesSent) /1024;
- int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived - lngBtyesReceived) /1024;
- // Update the labels
- lblInterfaceType.Text = nic.NetworkInterfaceType.ToString();
- lblUpload.Text = bytesSentSpeed.ToString() + " KB";
- lblDownload.Text = bytesReceivedSpeed.ToString() + " KB";
- //this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", ""));
- });
- }
- void timer_Tick(object sender, EventArgs e)
- {
- //InitializeNetworkInterface();
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- UpdateNetworkInterface();
- }
- private void cmbInterface_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void dialerCheck_Click(object sender, EventArgs e)
- {
- //Gateway IP
- NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
- foreach (NetworkInterface adapter in adapters)
- {
- IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
- GatewayIPAddressInformationCollection addresses =
- adapterProperties.GatewayAddresses;
- if (addresses.Count > 0)
- {
- foreach (GatewayIPAddressInformation address in addresses)
- {
- StatusTextBox.Text += "Gateway Address | " +
- address.Address.ToString() + "\r\n";
- }
- }
- }
- }
- private void Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- // timer.Dispose();
- // this.Dispose();
- }
- private void timer4dt_Tick(object sender, EventArgs e)
- {
- timelabel.Text = DateTime.Now.ToLongTimeString();
- timer4dt.Start();
- }
- private void resetStats_Click(object sender, EventArgs e)
- {
- _timer.Stop();
- _timerRunning = false;
- // Reset the elapsed time TimeSpan objects
- _totalElapsedTime = TimeSpan.Zero;
- _currentElapsedTime = TimeSpan.Zero;
- //label9.Text = "--";
- //label9.Text =0+"";
- }
- private void timerStart_Click_1(object sender, EventArgs e)
- {
- // If the timer isn't already running
- if (!_timerRunning)
- {
- // Set the start time to Now
- _startTime = DateTime.Now;
- // Store the total elapsed time so far
- _totalElapsedTime = _currentElapsedTime;
- _timer.Start();
- _timerRunning = true;
- }
- else // If the timer is already running
- {
- _startTime = DateTime.Now;
- // Store the total elapsed time so far
- _totalElapsedTime = _currentElapsedTime;
- _timer.Start();
- _timerRunning = true;
- }
- }
- private void timerdialer_Tick_1(object sender, EventArgs e)
- {
- {
- // We do this to chop off any stray milliseconds resulting from
- // the Timer's inherent inaccuracy, with the bonus that the
- // TimeSpan.ToString() method will now show correct HH:MM:SS format
- var timeSinceStartTime = DateTime.Now - _startTime;
- timeSinceStartTime = new TimeSpan(timeSinceStartTime.Hours,
- timeSinceStartTime.Minutes,
- timeSinceStartTime.Seconds);
- // The current elapsed time is the time since the start button was
- // clicked, plus the total time elapsed since the last reset
- _currentElapsedTime = timeSinceStartTime + _totalElapsedTime;
- }
- //TimeSpan t = TimeSpan.FromSeconds(seconds);
- //this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "\r\nDialer Disconnected!"));
- }
- private void timerStop_Click(object sender, EventArgs e)
- {
- _timer.Stop();
- _timerRunning = false;
- }
- // tafreh2 start
- protected void checknetstatusBoxMsg()
- {
- if (IsOnline(textBox1.Text) == true)
- {
- internetStatus.ForeColor = System.Drawing.Color.Green;
- string Status = "Internet Stauts: Connected by testing 8.8.8.8";
- internetStatus.Text = Status;
- this.StatusTextBox.AppendText(string.Format("{0}\r\n", Status));
- }
- else
- {
- internetStatus.ForeColor = System.Drawing.Color.Red;
- string Status = "Internet Stauts: DOWN by testing 8.8.8.8";
- this.StatusTextBox.AppendText(string.Format("{0}\r\n ", Status, "{0}\r\n\r\n"));
- }
- }
- protected void checkpppstatusBoxMsg()
- {
- this.Invoke((MethodInvoker)delegate
- {
- var conns = RasConnection.GetActiveConnections();
- var conn = conns.FirstOrDefault(o => o.EntryName == Globals.PPPNAME);
- if (conn != null)
- {
- string Status = "PPP Dialer Stauts: Connected";
- this.StatusTextBox.AppendText(string.Format("{0}\r\n", Status));
- }
- else
- {
- string Status = "PPP Dialer Stauts: Disconnected";
- this.StatusTextBox.AppendText(string.Format("{0}\r\n", Status));
- }
- });
- }
- // tafreh2 end
- private void netStatusButton_Click(object sender, EventArgs e)
- {
- checknetstatusBoxMsg();
- }
- private void dialerLanStatus_Click(object sender, EventArgs e)
- {
- checkpppstatusBoxMsg();
- }
- private void gatewayDetails_Click(object sender, EventArgs e)
- {
- //Gateway IP
- NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
- this.StatusTextBox.AppendText(string.Format("{0}\r\n", "Gateway Details!"));
- foreach (NetworkInterface adapter in adapters)
- {
- IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
- GatewayIPAddressInformationCollection addresses =
- adapterProperties.GatewayAddresses;
- if (addresses.Count > 0)
- {
- foreach (GatewayIPAddressInformation address in addresses)
- {
- this.StatusTextBox.AppendText(string.Format(address.Address.ToString() + "\r\n"));
- }
- }
- }
- }
- private void StatusTextBox_VisibleChanged(object sender, EventArgs e)
- {
- StatusTextBox.SelectionStart = textBox1.Text.Length;
- StatusTextBox.ScrollToCaret();
- }
- private void label5_Click(object sender, EventArgs e)
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment