{"id":12770,"date":"2023-01-31T10:00:00","date_gmt":"2023-01-31T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=12770"},"modified":"2023-02-01T12:16:09","modified_gmt":"2023-02-01T03:16:09","slug":"simple-command-line-chat-feature-of-netcat","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/12770","title":{"rendered":"Simple command line chat feature of netcat"},"content":{"rendered":"\n<p>Today, I would like to share about using netcat to send messages. Let\u2019s take a look.<\/p>\n\n\n\n<p>Netcat is a command line utility tool for performing operations about TCP or UDP and also known as a powerful networking tool. It is mostly used for port scanning, transfering data and troubleshooting a server but in this blog, I will share just about messaging using netcat.<\/p>\n\n\n\n<p>You can install netcat by the following command in debian based operating systems. You will find other installation methods for other operating systems by googling.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install netcat<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>To create a messaging service with netcat, run the following command in the terminal to listen on a port of the server.<\/p>\n\n\n\n<p>\/\/ Ross<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nc -lvp 2000<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"370\" height=\"88\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/01\/1.png\" alt=\"\" class=\"wp-image-12771\" \/><figcaption>Ross&#8217;s terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>And on the other system, run the following command to connect the chat server.<\/p>\n\n\n\n<p>\/\/ Rachel<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nc {ip_of_Ross} 2000<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"179\" height=\"68\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/01\/2.png\" alt=\"\" class=\"wp-image-12773\" \/><figcaption>Rachel&#8217;s terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Now Ross and Rachel can send message to each other.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"414\" height=\"144\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/01\/4.png\" alt=\"\" class=\"wp-image-12775\" \/><figcaption>Ross&#8217;s terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"214\" height=\"110\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/01\/5-1.png\" alt=\"\" class=\"wp-image-12776\" \/><figcaption>Rachel&#8217;s terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>But the messaging style is so simple that can\u2019t know obviously who sent the message. For that, you can add prepending name to the chat by using <strong>mawk<\/strong>.<\/p>\n\n\n\n<p>\/\/ Ross<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mawk -W interactive '$0=\"Ross: \"$0' | nc -l -v -p 2000<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\/\/ Rachel<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mawk -W interactive '$0=\"Rachel: \"$0' | nc {ip_of_Ross} 2000<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"606\" height=\"148\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/01\/6-1.png\" alt=\"\" class=\"wp-image-12777\" \/><figcaption>Ross&#8217;s terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"583\" height=\"112\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2023\/01\/7-1.png\" alt=\"\" class=\"wp-image-12778\" \/><figcaption>Rachel&#8217;s terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>There we go. It is cool, isn\u2019t it.<\/p>\n\n\n\n<p><em>For details of &#8216;nc&#8217; usage, run &#8216;man nc&#8217; in terminal.<\/em><\/p>\n\n\n\n<p>This is all for now. Hope you enjoy that.<\/p>\n\n\n\n<p>By Asahi<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12770\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/12770\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Simple command line chat feature of netcat\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12770\" data-text=\"Simple command line chat feature of netcat\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12770\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12770\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today, I would like to share about using netcat to send messages. Let\u2019s take a look. Netcat is a command line  [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12770"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=12770"}],"version-history":[{"count":5,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12770\/revisions"}],"predecessor-version":[{"id":12783,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12770\/revisions\/12783"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=12770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=12770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=12770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}