예제 #1
0
파일: Form1.cs 프로젝트: lili161/Easy
        private void button3_Click(object sender, EventArgs e)//刷新按钮点击事件
        {
            new Form2("已刷新,请移动端重新连接~").ShowDialog();
            Program.f.label2.Text      = "等待连接中···";
            Program.f.label2.ForeColor = Color.Black;

            soc.close();

            thread1.Abort();
            Console.WriteLine(thread1.IsAlive);
            soc     = new socket();
            thread1 = new Thread(new ThreadStart(soc.connect));
            thread1.Start();
        }
예제 #2
0
파일: Form1.cs 프로젝트: lili161/Easy
        private void Form1_Load(object sender, EventArgs e)
        {
            //string hostname = Dns.GetHostName();
            //IPHostEntry localhost = Dns.GetHostByName(hostname);
            //IPAddress localaddr = localhost.AddressList[3];
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;

            //label4.Text = localaddr.ToString();

            try
            {
                Process cmd = new Process();
                cmd.StartInfo.FileName  = "ipconfig.exe"; //设置程序名
                cmd.StartInfo.Arguments = "/all";         //参数
                                                          //重定向标准输出
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.RedirectStandardInput  = true;
                cmd.StartInfo.UseShellExecute        = false;
                cmd.StartInfo.CreateNoWindow         = true; //不显示窗口(控制台程序是黑屏)
                                                             //cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;          //暂时不明白什么意思

                /*
                 * 收集一下 有备无患
                 * 关于:ProcessWindowStyle.Hidden隐藏后如何再显示?
                 * hwndWin32Host = Win32Native.FindWindow(null, win32Exinfo.windowsName);
                 * Win32Native.ShowWindow(hwndWin32Host, 1);          //先FindWindow找到窗口后再ShowWindow
                 */
                cmd.Start();
                string info = cmd.StandardOutput.ReadToEnd();
                cmd.WaitForExit();
                cmd.Close();
                if (info.Contains("WLAN"))
                {
                    info = info.Substring(info.IndexOf("WLAN"));
                    info = info.Substring(info.IndexOf("IPv4"));
                    info = info.Substring(info.IndexOf(":") + 1);
                    int end = info.IndexOf("(");
                    info        = info.Substring(0, end);
                    label4.Text = info;
                }
                else
                {
                    info = info.Substring(info.IndexOf("无线"));
                    info = info.Substring(info.IndexOf("IPv4"));
                    info = info.Substring(info.IndexOf(":") + 1);
                    int end = info.IndexOf("(");
                    info        = info.Substring(0, end);
                    label4.Text = info;
                }
            }
            catch (System.NullReferenceException)
            {
                //do nothing
            }
            label2.Text = "等待连接中···";
            Program.f.label2.ForeColor = Color.Black;
            soc     = new socket();
            thread1 = new Thread(new ThreadStart(soc.connect));
            thread1.Start();
            Console.WriteLine(soc.ToString());
        }