Saturday, May 19, 2012

NetCat in Java

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.

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.

The code and executable for Java version of NetCat is available on GitHub:
http://github.com/rafalrusin/netcat/downloads

I used Jakarta Commons CLI to handle commandline parameters. The code is as simple as that:



In order to handle stream I/O I implemented a simple StreamTransferer class like this:



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't receive any response back from server. So instead of doing that I had to use Socket shutdownOutput method, like in the code below.



It worked perfectly then.

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. The example looks like below:


27 comments:

  1. Hi ,

    i want to sent command via netcat by connect method. But i dont know make this.

    example :

    connect("192.168.2.104", 6000 ,"ifconfig" ) like this.

    pls help me

    ReplyDelete
  2. I read a weblog, I hope that it doesn't sadden me as much as this one. I’m talking about, I know it was my selection to read, but I actually thought you'd have something interesting to say. Great work admin..
    SAT coaching chennai

    ReplyDelete
  3. You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.

    angularjs-Training in velachery

    angularjs Training in chennai

    angularjs-Training in pune

    angularjs-Training in chennai

    angularjs Training in chennai

    ReplyDelete
  4. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    microsoft azure training in bangalore
    rpa training in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete

  5. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you.
    Keep update more information..


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium interview questions and answers

    ReplyDelete
  6. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
    Data science Course Training in Chennai | No.1 Data Science Training in Chennai
    RPA Course Training in Chennai | No.1 RPA Training in Chennai

    ReplyDelete


  7. افضل ادوات تنظيف وتعقيم خزانات المياه


    تعد الاول افضل شركة تنظيف خزانات بالمدينة المنورة تعمل على استخدام

    ReplyDelete
  8. Such a great information for blogger i am a professional blogger thanks…

    Get Best SAP HR HCM Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.

    ReplyDelete
  9. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great post



    Any one looking for digital marketing Kindly visit us @ online idea lab


    ReplyDelete
  10. Thanks for Sharing This Article.It is very so much valuable content. . AWS course in Chennai

    ReplyDelete
  11. Thanks For Sharing
    100% Job Guarantee Classes In Mumbai
    https://www.sevenmentor.com/100-job-guarantee-courses-in-mumbai

    ReplyDelete
  12. Really nice and informative blog, keep it up. Thanks for sharing and I have some suggestions.
    Click Here For Visit My Site thanks .

    ReplyDelete
  13. Kitapları Aşk
    Youtube Abone Satın al .
    Cami Avizesi
    Cami Avizeleri
    Avize Cami
    First Deposit Bonus Dollar forex 2021
    Takipçi Satın al .
    Takipçi Satın al .
    Takipçi Satın al .
    Takipcialdim.com/tiktok-takipci-satin-al/
    Instagram Beğeni Satın al .
    Instagram Beğeni Satın al .
    Btcturk
    Tiktok Izlenme Satın al
    sms onay
    youtube izlenme satın al
    no deposit bonus forex 2021
    tiktok jeton hilesi
    tiktok beğeni satın al
    binance
    takipçi satın al
    uc satın al
    sms onay
    sms onay
    tiktok takipçi satın al
    tiktok beğeni satın al satın al
    twitter
    Topic Satın al . Trend
    Youtube Abone Satın al .
    Instagram Beğeni Satın al .
    Tiktok Beğeni Satın al .
    facebook twitter Takipçi al . Satın
    Trend Topic Satın al .
    Youtube Abone Satın al .
    Takipcialdim.com/instagram-begeni-satin-al/
    Perde Modelleri
    Instagram Takipçi Satın al .
    Instagram Takipçi Satın al .
    takipçi satın al
    instagram takipçi satın al

    ReplyDelete
  14. Do you want to make a video about netcat for youtube? From this website https://soclikes.com you can get many likes and views for your video

    ReplyDelete
  15. Thanks for sharing informative post. Are looking for best Tamil typing tool online, make use of our Tamil typing software to make translation faster. Thirumana Porutham in Tamil | Samacheer Kalvi Books PDF

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete