{"id":9374,"date":"2023-07-17T22:22:20","date_gmt":"2023-07-17T20:22:20","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=9374"},"modified":"2024-09-18T14:23:25","modified_gmt":"2024-09-18T12:23:25","slug":"powershell-udp-client-and-server","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-udp-client-and-server\/","title":{"rendered":"Powershell: UDP Client and Server"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_9374 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_9374')){$('.twoclick_social_bookmarks_post_9374').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20UDP%20Client%20and%20Server\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athese%20UDP%20client%20and%20server%20and%20simply%20used%20for%20testing%20if%20a%20specific%20UDP%20port%20is%20open%0D%0A%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/powershell-udp-client-and-server\\\/\",\"post_id\":9374,\"post_title_referrer_track\":\"Powershell%3A+UDP+Client+and+Server\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>these UDP client and server and simply used for testing if a specific UDP port is open<\/p>\n<p><!--more--><\/p>\n<p>This is the server side. It listens at port 4444<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Server\r\n$iPort = 4444\r\n$Listen = New-Object System.Net.IPEndPoint (&#x5B;IPAddress]::Any , $port)\r\n$oSocket = New-Object System.Net.Sockets.UdpClient($iPort)\r\n        while($true) {\r\n          $aContent = $oSocket.Receive(&#x5B;ref]$Listen)\r\n          &#x5B;Text.Encoding]::ASCII.GetString($aContent)\r\n      }\r\n$oSocket.Close() \r\n<\/pre>\n<p>And the client side<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Client\r\n$iPort = 4444\r\n$sSendToHost=&quot;localhost&quot;\r\n$oSocket = New-Object System.Net.Sockets.UdpClient\r\n$aMessage=&#x5B;System.Text.Encoding]::ASCII.GetBytes(&quot;TEST 1234&quot;)\r\n$oSocket.Send($aMessage ,$aMessage.Length,$sSendToHost,$iPort)\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, these UDP client and server and simply used for testing if a specific UDP port is open<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,5],"tags":[180,1990,640,1991],"class_list":["post-9374","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-windowsknowhow","tag-client","tag-powerhsell","tag-server","tag-udp"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=9374"}],"version-history":[{"count":5,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9374\/revisions"}],"predecessor-version":[{"id":9879,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9374\/revisions\/9879"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=9374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=9374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=9374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}