{"id":118,"date":"2022-05-17T18:29:16","date_gmt":"2022-05-17T10:29:16","guid":{"rendered":"https:\/\/blog.purewind.top\/?p=118"},"modified":"2024-10-15T21:03:08","modified_gmt":"2024-10-15T13:03:08","slug":"c%e8%bf%9c%e6%8e%a7%e7%a8%8b%e5%ba%8f%e3%81%ae%e5%88%9d%e4%bd%93%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/foreverhome.live\/index.php\/2022\/05\/17\/c%e8%bf%9c%e6%8e%a7%e7%a8%8b%e5%ba%8f%e3%81%ae%e5%88%9d%e4%bd%93%e9%aa%8c\/","title":{"rendered":"\u3010C#\u3011\u8fdc\u63a7\u7a0b\u5e8f\u306e\u521d\u4f53\u9a8c"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p class=\"has-light-green-cyan-color has-text-color\"><strong>\u4f7f\u7528\u7684\u8f6f\u4ef6\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Visual Studio<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"has-light-green-cyan-color has-text-color\"><strong>\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>C#<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>Github\uff1a<a href=\"https:\/\/github.com\/Mangofang\/MonitorServer\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/github.com\/Mangofang\/MonitorServer<\/a><\/p>\n\n\n\n<p>Github\uff1a<a href=\"https:\/\/github.com\/Mangofang\/WindowsSystemMessage\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/github.com\/Mangofang\/WindowsSystemMessage<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p class=\"has-text-align-center has-light-green-cyan-color has-text-color has-medium-font-size\"><strong>\u793a\u610f\u56fe<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2022\/05\/Untitled-1.jpg\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 695px; --smush-placeholder-aspect-ratio: 695\/90;\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p class=\"has-medium-font-size\">1<strong>.\u8fdc\u63a7\u7aef<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>\u8fd9\u91cc\u65b0\u5efa\u4e86\u4e00\u4e2a\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u6765\u7f16\u5199\u8fdc\u63a7\u7aef<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2022\/05\/QQ\u622a\u56fe20220517173915.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 526px; --smush-placeholder-aspect-ratio: 526\/107;\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>\u8bbe\u7f6e\u76d1\u542c\uff0c\u540e\u7eed\u5ba2\u6237\u7aef\uff08\u88ab\u63a7\u7aef\uff09\u53ea\u9700\u8981\u8fde\u63a5\u8fdc\u63a7\u7aef\u76d1\u542c\u7aef\u53e3\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Console.WriteLine(\"\u952e\u5165\u672c\u5730IP\u5730\u5740\");\nIPAddress ip = IPAddress.Parse(Console.ReadLine());\nConsole.WriteLine(\"\u952e\u5165\u76d1\u542c\u7aef\u53e3\");\nint port = int.Parse(Console.ReadLine());\nTcpListener myList = new TcpListener(ip, port);\nmyList.Start();\nConsole.WriteLine(\"\u5f00\u542f\u76d1\u542c:\" + myList.LocalEndpoint);\n\nSocket s = myList.AcceptSocket();\nConsole.WriteLine(\"\u8fde\u63a5\u6765\u81ea \" + s.RemoteEndPoint);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>\u5efa\u7acb\u8fde\u63a5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Socket s = myList.AcceptSocket();\nConsole.WriteLine(\"\u8fde\u63a5\u6765\u81ea \" + s.RemoteEndPoint);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>\u5efa\u7acb\u6d41\u4f20\u8f93\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>            while (s.Connected)\n            {\n                try\n                {\n                    ASCIIEncoding asen = new ASCIIEncoding();\n                    Console.WriteLine(\"\u952e\u5165\u6307\u4ee4\");\n                    s.Send(asen.GetBytes(Console.ReadLine()));\n                    byte&#91;] b = new byte&#91;30000];\n                    int k = s.Receive(b);\n                    string a = \"\";\n                    for (int i = 0; i &lt; k; i++)\n                    {\n                        a += Convert.ToChar(b&#91;i]);\n                    }\n                    Console.WriteLine(a);\n                }\n                catch (SocketException)\n                {\n                    Console.WriteLine(\"\u8fdc\u7a0b\u4e3b\u673a\u5f3a\u8feb\u5173\u95ed\u4e86\u8fde\u63a5\");\n                    s = myList.AcceptSocket();\n                    Console.WriteLine(\"\u8fde\u63a5\u6765\u81ea \" + s.RemoteEndPoint);\n                }\n\n            }<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2.\u5ba2\u6237\u7aef\uff08\u88ab\u63a7\u7aef\uff09<\/strong><\/p>\n\n\n\n<p>\u5efa\u7acb\u4e0e\u8fdc\u63a7\u7aef\u8fde\u63a5\uff0c<\/p>\n\n\n\n<p><strong>\u6ce8\uff1a\u8fd9\u91ccIP\u5730\u5740\u9700\u8981\u586b\u5199\u8fdc\u63a7\u673a\u7684\u516c\u7f51IP\u5730\u5740\uff0c\u8fdc\u63a7\u673a\u9700\u8981\u63d0\u524d\u5728\u9632\u706b\u5899\u653e\u884c\u76d1\u542c\u7aef\u53e3<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>            TcpClient tcpClient = new TcpClient();\n            tcpClient.Connect(\"IP\u5730\u5740\", \u7aef\u53e3);\n            Console.WriteLine(\"\u5df2\u4e0e\u8fdc\u63a7\u7aef\u5efa\u7acb\u8fde\u63a5!\");\n\n            Stream stm = tcpClient.GetStream();<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>\u63a5\u6536\u6307\u4ee4\uff0c\u5c06\u63a5\u6536\u7684\u6307\u4ee4\u5199\u5165switch\u4e2d\u5339\u914d\u5bf9\u5e94\u7684\u6307\u4ee4\uff0c\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u4e86\u201cnotepad\u201d\u6307\u4ee4\uff0c\u4f7f\u7528\u8fdc\u63a7\u7aef\u952e\u5165\u201cnotepad\u201d\u5728\u88ab\u63a7\u673a\u4e2d\u6253\u5f00\u8bb0\u4e8b\u672c\uff0c\u5f53\u7136\u8fd8\u80fd\u7ee7\u7eed\u5728switch\u4e2d\u6dfb\u52a0\u5176\u4ed6\u6307\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>            ASCIIEncoding asen = new ASCIIEncoding();\n            byte&#91;] remessage = null;\n\n            while (tcpClient.Connected)\n            {\n                byte&#91;] bb = new byte&#91;100];\n                int k = stm.Read(bb, 0, 100);\n                string a = \"\";\n                for (int i = 0; i &lt; k; i++)\n                {\n                    a += Convert.ToChar(bb&#91;i]);\n                }\n                switch (a)\n                {\n                    case \"notepad\":\n                        Process process = new Process();\n                        process.StartInfo.FileName = \"cmd.exe\";\n                        process.StartInfo.Arguments = \"\/c\" + \"start notepad\";\n                        process.StartInfo.UseShellExecute = false;\n                        process.StartInfo.CreateNoWindow = true;\n                        process.Start();\n                        process.WaitForExit();\n                        process.Close();\n\n                        remessage = asen.GetBytes(\"Complete!\");\n                        break;\n                    default:\n                        remessage = asen.GetBytes(\"Can't find this command\");\n                        break;\n                }\n                stm.Write(remessage, 0, remessage.Length);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2022\/05\/QQ\u622a\u56fe20220517182633-1024x374.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/374;\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2022\/05\/QQ\u622a\u56fe20220517182708-1024x657.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/657;\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-css-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u7684\u8f6f\u4ef6\uff1a \u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff1a Github\uff1ahttps:\/\/github.com\/Mangofang\/MonitorServer &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-program"],"_links":{"self":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":2,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":1610,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts\/118\/revisions\/1610"}],"wp:attachment":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}