Ejemplo n.º 1
0
        void LoadIPaddress()
        {
            this.Cursor = Cursors.WaitCursor;
            Process netUtility = new Process();

            netUtility.StartInfo.FileName               = "arp";
            netUtility.StartInfo.CreateNoWindow         = true;
            netUtility.StartInfo.Arguments              = "-a";
            netUtility.StartInfo.RedirectStandardOutput = true;
            netUtility.StartInfo.UseShellExecute        = false;
            netUtility.StartInfo.RedirectStandardError  = true;
            netUtility.Start();

            StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);

            String line = "", pcname = "", ipaddr;

            streamReader.ReadLine();
            streamReader.ReadLine(); //Skipping First 3 Lines
            streamReader.ReadLine();

            while ((line = streamReader.ReadLine()) != null)
            {
                if (line.Substring(line.Length - 10, 1) == "d") //Allowing only Dynamic IPs
                {
                    try
                    {
                        ipaddr = line.Substring(2).Substring(0, line.Substring(2).IndexOf(" "));
                        pcname = System.Net.Dns.GetHostEntry(ipaddr).ToString();
                        DGV_LoadUsers.Rows.Add(pcname, ipaddr);
                    }
                    catch
                    {
                        //If no such host found, skip it
                    }
                }
            }
            MessageBox.Show("Done Load final");
            streamReader.Close();
            netUtility.WaitForExit(1);
            DGV_LoadUsers.ClearSelection();
            this.Cursor = Cursors.Default;
        }
Ejemplo n.º 2
0
        void LoadIPaddress()
        {
            this.Cursor = Cursors.WaitCursor;
            Process netUtility = new Process();

            netUtility.StartInfo.FileName               = "net.exe";
            netUtility.StartInfo.CreateNoWindow         = true;
            netUtility.StartInfo.Arguments              = "view";
            netUtility.StartInfo.RedirectStandardOutput = true;
            netUtility.StartInfo.UseShellExecute        = false;
            netUtility.StartInfo.RedirectStandardError  = true;
            netUtility.Start();

            StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);

            string line = "";

            while ((line = streamReader.ReadLine()) != null)
            {
                if (line.StartsWith("\\"))
                {
                    try
                    {
                        pcname = line.Substring(2).Substring(0, line.Substring(2).IndexOf(" "));
                        ipaddr = Dns.GetHostByName(pcname).AddressList[0].ToString();
                        DGV_LoadUsers.Rows.Add(pcname, ipaddr);
                    }
                    catch
                    {
                        MessageBox.Show("\"" + pcname + "\" is shutdown and creating network issues..\n Please restart system...", "Be Connect+ - Network Issue", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            streamReader.Close();
            netUtility.WaitForExit(1);
            DGV_LoadUsers.ClearSelection();
            this.Cursor = Cursors.Default;
        }