{"id":156,"date":"2005-05-19T02:27:35","date_gmt":"2005-05-19T09:27:35","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=156"},"modified":"2005-05-19T02:27:35","modified_gmt":"2005-05-19T09:27:35","slug":"portscanner-only-60-lines-of-code","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/portscanner-only-60-lines-of-code\/","title":{"rendered":"PortScanner &#8211; Only 60 lines of code"},"content":{"rendered":"\n<p>Hi, here&#8217;s a simple port scanner I wrote today in Java.<br \/>\nI needed to see something on my server, perhaps you can find it useful. I would say its pretty fast, you can tweak the number of threads and timeouts to adjust to your server\/connection. I did&#8217;t do much testing on it, just a few tweaks and I was happy with the speed of it.<\/p>\n<p>Good for learning a bit of Java (Threads, Sockets)<\/p>\n<pre>\nimport java.net.*;\nimport java.util.*;\nimport java.io.*;\n\n\/** \n By Gubatron - 05-18-2005 \n Simple Fast Port Scanner\n*\/\npublic class PortScanner implements Runnable {\n    int port;\n    static int MAX_PORT = 65536;\n    static int THREADS = 0;\n    static int MAX_THREADS = 250;\n    static int TIMEOUT = 50;\n    static String TARGET = new String(\"www.yahoo.com\");\n\n    public PortScanner(int p) {\n        this.port = p;\n    };\n\n\n    public synchronized void run() {\n\n        THREADS++;\n\n\n        try {\n            Socket s = new Socket();\n\n            s.connect(new InetSocketAddress(TARGET,this.port), \n                      TIMEOUT);\n            System.out.println(\"Port \" + this.port + \" is open\");\n            s.close();\n        } catch (Exception e) {\n        }\n\n        THREADS--;\n\n    }\n\n    public static void main(String[] args) {\n        if (args.length &gt; 0) {\n            TARGET = args[0];\n        }\n\n        System.out.println(\"PortScanner By Gubatron (May-2005)\");\n        System.out.println(\"Scanning Ports On: \" + TARGET + \"n\");\n\n        for (int i=21; i &lt;= MAX_PORT; i++) {\n            if (PortScanner.THREADS &gt; PortScanner.MAX_THREADS) {\n                i--;\n                continue;\n            }\n\n            PortScanner pokie = new PortScanner(i);\n            Thread t = new Thread(pokie);\n            t.start();\n        }\n    }\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hi, here&#8217;s a simple port scanner I wrote today in Java. I needed to see something on my server, perhaps you can find it useful. I would say its pretty fast, you can tweak the number of threads and timeouts to adjust to your server\/connection. I did&#8217;t do much testing on it, just a few [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[33],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-gubatron"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-2w","jetpack-related-posts":[{"id":1269,"url":"https:\/\/www.gubatron.com\/blog\/how-to-make-a-quick-dirty-hexviewer-updated\/","url_meta":{"origin":156,"position":0},"title":"How to make a Quick &#038; Dirty HexViewer &#8211; Updated","author":"gubatron","date":"April 20, 2009","format":false,"excerpt":"After I received comments from ispak on Flickr I made a few fixes. ispak pointed out that it was a bad idea reading one byte at the time, also I had a gay ass try\/catch that didn't catch any exception :p So now I read 16 byte chunks, and I\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"HexViewer - r2","src":"https:\/\/i0.wp.com\/farm4.static.flickr.com\/3486\/3458529439_31357e0afe_o.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/farm4.static.flickr.com\/3486\/3458529439_31357e0afe_o.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/farm4.static.flickr.com\/3486\/3458529439_31357e0afe_o.png?resize=525%2C300 1.5x"},"classes":[]},{"id":980,"url":"https:\/\/www.gubatron.com\/blog\/javareflection-notes-invoking-a-static-main-method-from-a-dinamically-loaded-class\/","url_meta":{"origin":156,"position":1},"title":"Java\/Reflection notes: Invoking a static main() method from a dinamically loaded class.","author":"gubatron","date":"November 22, 2008","format":false,"excerpt":"Maybe for some wild reason, your Java application will need to execute a pre launcher that won't know about the Main class it's supposed to invoke until it's being executed. For example, you have distributed your Java application but you used pack200 to compress your jars, and your new application\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2792,"url":"https:\/\/www.gubatron.com\/blog\/java-have-a-jtables-column-preferred-width-adjusted-to-perfectly-to-the-size-of-the-longest-string-in-the-model\/","url_meta":{"origin":156,"position":2},"title":"Java: Have a JTable&#8217;s column preferred width adjusted perfectly to the size of the longest string in the model","author":"gubatron","date":"October 30, 2012","format":false,"excerpt":"Here's a utility method I've coded for FrostWire's partial download dialog. With it I'm able to adjust a JTable's column by iterating over the table's column model data and calculating the exact dimensions required to render the longest string found. You can specify a maximum width (to avoid some really\u2026","rel":"","context":"In \"java\"","block_context":{"text":"java","link":"https:\/\/www.gubatron.com\/blog\/tag\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2047,"url":"https:\/\/www.gubatron.com\/blog\/map-function-in-java\/","url_meta":{"origin":156,"position":3},"title":"Map function in Java","author":"gubatron","date":"August 31, 2010","format":false,"excerpt":"I read on some email signature something along the lines of: \"If I had a dollar for every for(int i=0; i < size; i++) { ... } I've written I'd be rich\" After coding on Android and learning about some of the tips for performance, like \"With an ArrayList, a\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2063,"url":"https:\/\/www.gubatron.com\/blog\/android-programming-how-to-obtain-the-wifis-corresponding-networkinterface\/","url_meta":{"origin":156,"position":4},"title":"Android: How to obtain the WiFi&#8217;s corresponding NetworkInterface","author":"gubatron","date":"September 19, 2010","format":false,"excerpt":"Let's say for some odd reason in the world you do need to get the corresponding NetworkInterface object of the Wifi on your android, in my case I needed to have my WiFi device send multicast packets, and I wanted my MulticastSocket to only send packets through the WiFi device\u2026","rel":"","context":"In &quot;Android&quot;","block_context":{"text":"Android","link":"https:\/\/www.gubatron.com\/blog\/category\/android\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1928,"url":"https:\/\/www.gubatron.com\/blog\/droid-vs-nexus-1-who-can-calculate-md5-faster\/","url_meta":{"origin":156,"position":5},"title":"Droid vs Nexus 1: Who can calculate MD5 faster?","author":"gubatron","date":"May 21, 2010","format":false,"excerpt":"Nexus 1 indeed. 17 files get their MD5 calculated on the Droid and 17 files get their MD5 hash calculated on the Nexus 1 Nexus 1 pwns. Here's the code in case you're curious. [java] public void onClick(View v) { _logTextView.setText(\"MD5 Benchmark on \" + Build.DEVICE + \"nn\"); if (GlobalVariables.APP_CONTEXT\u2026","rel":"","context":"In &quot;Android&quot;","block_context":{"text":"Android","link":"https:\/\/www.gubatron.com\/blog\/category\/android\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}