{"id":2361,"date":"2018-08-01T04:48:59","date_gmt":"2018-07-31T19:48:59","guid":{"rendered":"http:\/\/okamurax.com\/?p=2361"},"modified":"2018-08-01T04:48:59","modified_gmt":"2018-07-31T19:48:59","slug":"c-%e5%ae%9a%e6%9c%9f%e7%9a%84%e3%81%ab%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e5%ae%9f%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=2361","title":{"rendered":"C# \u5b9a\u671f\u7684\u306b\u30b3\u30de\u30f3\u30c9\u5b9f\u884c"},"content":{"rendered":"<p>\u5b9a\u671f\u7684\u306btracert\u3092\u5b9f\u884c\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Drawing;\r\nusing System.IO;\r\nusing System.Text.RegularExpressions;\r\nusing System.Diagnostics;\r\nusing System.Windows.Forms;\r\n\r\nnamespace Tracert\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n\r\n            WindowState = FormWindowState.Minimized;\r\n            ShowInTaskbar = false;\r\n\r\n            Bitmap bitmap = new Bitmap(32, 32);\r\n            Graphics graphics = Graphics.FromImage(bitmap);\r\n            graphics.FillRectangle(Brushes.Green, graphics.VisibleClipBounds);\r\n\r\n            NotifyIcon notifyIcon = new NotifyIcon();\r\n            notifyIcon.Icon = Icon.FromHandle(bitmap.GetHicon());\r\n            notifyIcon.Visible = true;\r\n            notifyIcon.Click += new EventHandler((object sender, EventArgs e) =&gt; {\r\n                MessageBox.Show(\"\u7d42\u4e86\u3057\u307e\u3059\u3002\");\r\n                Application.Exit();\r\n            });\r\n\r\n            Timer timer = new Timer();\r\n            timer.Interval = 3600000;\r\n\r\n            timer.Tick += new EventHandler((object sender, EventArgs e)=&gt; {\r\n                Execute();\r\n            });\r\n            timer.Start();\r\n        }\r\n\r\n        private void Execute()\r\n        {\r\n            using (Process process = new Process())\r\n            {\r\n                process.StartInfo.RedirectStandardOutput = true;\r\n                process.StartInfo.CreateNoWindow = true;\r\n                process.StartInfo.UseShellExecute = false;\r\n                process.StartInfo.FileName = \"tracert\";\r\n                process.StartInfo.Arguments = \"192.168.5.1\";\r\n                process.Start();\r\n\r\n                string result = \"\";\r\n                using (StringReader sr = new StringReader(process.StandardOutput.ReadToEnd()))\r\n                {\r\n                    Regex regex = new Regex(@\"ms\");\r\n                    while (sr.Peek() &gt; -1)\r\n                    {\r\n                        string ln = sr.ReadLine();\r\n                        if (regex.IsMatch(ln)) result += ln;\r\n                    }\r\n                }\r\n                process.WaitForExit();\r\n                result = DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\") + \" \" + result;\r\n\r\n                using (StreamWriter sw = new StreamWriter(Application.StartupPath + @\"\\dat.txt\", true, System.Text.Encoding.UTF8))\r\n                {\r\n                    sw.Write(result + \"\\r\\n\");\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u671f\u7684\u306btracert\u3092\u5b9f\u884c\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3002 using System; using System.Drawing; using System.IO; using System.Text.RegularExpressio &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=2361\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# \u5b9a\u671f\u7684\u306b\u30b3\u30de\u30f3\u30c9\u5b9f\u884c&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-2361","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2361"}],"version-history":[{"count":1,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2361\/revisions"}],"predecessor-version":[{"id":2362,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2361\/revisions\/2362"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}