Exemplo n.º 1
0
        static void Main(string[] args)
        {
            FileOperation       file = new FileOperation();
            ConnectHostWithPing Conn = file.generateHostList();
            string header = string.Format("{0}\t{1}\t\t\t{2}", "Host名稱", "IPv4位址", "狀態");
            string Column = ""; string host = "";  string ip = "";  string command = "";

            Console.WriteLine(header);
            for (int i = 0; i <= Conn.getIpListLength() - 1; i++)
            {
                Column += Conn.connectInfo() + "\n";
                Conn.next();
            }
            Console.WriteLine(Column);

            while (true)
            {
                Column = "";
                Conn.initIndex();
                Console.WriteLine("\n Add Or Remove Or Ping \n");
                command = Console.ReadLine();
                if (command == "Add")
                {
                    Console.Write("Host:\t"); host = Console.ReadLine();
                    Console.Write("IP:\t");   ip   = Console.ReadLine();
                    Conn.inesertHostAndIp(host, ip);
                    FileOperation csv = new FileOperation();
                    csv.saveFile(Conn);
                }
                else if (command == "Remove")
                {
                    Console.Write("輸入欲刪除的IP:");
                    string removeIp = Console.ReadLine();
                    Conn.RemoveByIp(removeIp);
                    FileOperation csv = new FileOperation();
                    csv.saveFile(Conn);
                }
                else if (command == "Ping")
                {
                    for (int i = 0; i <= Conn.getIpListLength() - 1; i++)
                    {
                        Column += Conn.connectInfo() + "\n";
                        Conn.next();
                    }
                    Console.WriteLine(Column);
                }
            }
        }
Exemplo n.º 2
0
        public void saveFile(ConnectHostWithPing data)
        {
            string hostList = "";

            for (int i = 0; i <= data.getIpListLength() - 1; i++)
            {
                hostList += data.makeHostList() + "\n";
                data.next();
            }
            try
            {
                FileStream   FileStream = new FileStream(appath, FileMode.Create);
                StreamWriter sw         = new StreamWriter(FileStream, System.Text.Encoding.UTF8);
                sw.WriteLine(hostList);
                sw.Flush();
                sw.Close();
                FileStream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }