{"id":2970,"date":"2012-05-19T20:21:00","date_gmt":"2012-05-19T19:21:00","guid":{"rendered":"http:\/\/touk.pl\/blog\/?guid=e48ffe118b292cab6bf13fe28d3b5328"},"modified":"2023-03-20T13:09:24","modified_gmt":"2023-03-20T12:09:24","slug":"netcat-in-java","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2012\/05\/19\/netcat-in-java\/","title":{"rendered":"NetCat in Java"},"content":{"rendered":"<p>Recently, I tried to run netcat under Windows and I failed to compile it. So I decided to write a simple equivalent in Java, which works under all platforms.<\/p>\n<p>NetCat is a very simple and useful tool, which allows to see contents of TCP\/IP requests, like HTTP etc., both server and client side. With NetCat it is possible to either set up TCP\/IP listener on a port and receive data or send TCP\/IP request to remote server.<\/p>\n<p>The code and executable for Java version of NetCat is available on GitHub:<br \/>\n<a href=\"http:\/\/github.com\/rafalrusin\/netcat\/downloads\">http:\/\/github.com\/rafalrusin\/netcat\/downloads<\/a><\/p>\n<p>I used Jakarta Commons CLI to handle commandline parameters. The code is as simple as that:<\/p>\n<p>In order to handle stream I\/O I implemented a simple StreamTransferer class like this:<\/p>\n<p>The only issue I had was that whenever I closed Java I\/O stream using OutputStream.close(), it was closing the whole socket. So I couldn&#8217;t receive any response back from server. So instead of doing that I had to use Socket shutdownOutput method, like in the code below.<\/p>\n<p>It worked perfectly then.<\/p>\n<p>So it is possible to send HTTP GET requests to google using this tool. In order to do that, you need to connect to google.com and type GET and enter. CTRL+Z and enter is for closing input stream under Windows. CTRL+D is for Linux. <\/p>\n","protected":false},"excerpt":{"rendered":"Recently, I tried to run netcat under Windows and I failed to compile it. So I decided to&hellip;\n","protected":false},"author":35,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[68,537,694],"class_list":{"0":"post-2970","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"tag-java","8":"tag-shell","9":"tag-touk-internals"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/2970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=2970"}],"version-history":[{"count":7,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/2970\/revisions"}],"predecessor-version":[{"id":15362,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/2970\/revisions\/15362"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=2970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=2970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=2970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}