permaculture playing cards*
The moose likes Sockets and Internet Protocols and the fly likes port scanning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "port scanning " Watch "port scanning " New topic
Author

port scanning

dashang trivedi
Greenhorn

Joined: Mar 01, 2010
Posts: 26
i try to check....which port is busy...or listen mode......

but its give EXCEPTION.......



ITS GIVE AN EXCEPTION
java.net.ConnectException: Connection refused: connect

My objective is if i open yahoo page that means port 80 HTTP is active....so its must in listen mode ....but why my code is give Exception
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

Connection refused means you cannot connect on the port. Are you sure it's open?

And you should close your sockets.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11527
    
100

I believe your basic assumption is incorrect. Namely:
dashang trivedi wrote:My objective is if i open yahoo page that means port 80 HTTP is active....so its must in listen mode ....but why my code is give Exception


If you open a yahoo page, then it means that yahoo.com is listening on port 80. Not you. Think about this from the perspective of what a web browser does (in normal mode): if you tell your web browser to connect to yahoo.com, the browser has to know what port to connect to: it defaults to assuming that yahoo will be listening on port 80, so it is relatively easy to connect their. Likewise, if you were to run a web server on your personal computer, browsers would assume that they can connect to you using port 80.

But if you have a web server on your personal computer that is using port 80, does that mean that you cannot make outgoing connections to any other web server?

To put that another way: the other web server does not care what port you are using as your outgoing port: it only cares about what port it must listen to. So you can use port 6000 on your computer to connect to port 80 on the yahoo.com servers, and that way your local port 80 is free for you to run your own personal web server.

If I look at my current outgoing connections to coderanch.com, I see:

From that I can see that I do not have a single local connection to coderanch.com that uses port 80. I have ports 55257 ... 55262 on my personal computer that are all connecting to coderanch.com

Make sense?


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
dashang trivedi
Greenhorn

Joined: Mar 01, 2010
Posts: 26
so sir is it possible .....if i open yahoo.com or any site which use HTTP protocol ...then LOG the entry...which store source address ,destination address,port ....
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11527
    
100

Not with Java directly.

You would need to know the operating system on use on the computer you wish to monitor, and you would need administrator access to it. Then you could install some software into the protocol stack to track this.

There is a huge legal minefield here. I suggest you talk to your system administrators for simpler solutions that are legal in your jurisdiction.
dashang trivedi
Greenhorn

Joined: Mar 01, 2010
Posts: 26
sir i want to develop that code ...
i m stop just because how the event is call i m not getting.....how any event is call when ip request is sending or receiving..

is it possible in java to manipulate the ip layer of network communication. Basically I want to be able to get my hands on packets BEFORE their port is resolved and they're passed onto their service application

Can you please tell me the way.....what to do....just abstract view... then i develop the code...and post it...

so many software are available in market like wire-shark,tcpdump,snort they store the ip address log....

so i think it can be develop in java also....
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11527
    
100

dashang trivedi wrote:is it possible in java to manipulate the ip layer of network communication. Basically I want to be able to get my hands on packets BEFORE their port is resolved and they're passed onto their service application

This is not possible with Java.

To get your hands on the packets at that low level, you will have to develop code in a language that can access the low level drivers and will compile to native machine language on the platform it is to be deployed on.

Java compiles to byte code, not to native machine code. And in order to maintain cross-platform compatibility it does not access the drivers at such a low level.

dashang trivedi wrote:so many software are available in market like wire-shark,tcpdump,snort they store the ip address log....

  • wire-shark is developed in C
  • tcpdump is developed in C
  • snort is developed in C


  • dashang trivedi wrote:so i think it can be develop in java also....

    While I admire your zeal for developing this in Java, I think you are bound for disappointment. Different languages are just tools to be used, and are not always interchangeable. It is said that to the man with a hammer, every problem is a nail: this sounds like what you are trying to do here. Java and C are two different languages that each have good and bad points. This is the sort of problem that can be solved using C (not easily, but it can be done). This is not the sort of problem that Java is meant to solve.
    Elchin Asgarli
    Ranch Hand

    Joined: Mar 08, 2010
    Posts: 222

    Andrew Monkhouse wrote:Not with Java directly.

    You would need to know the operating system on use on the computer you wish to monitor, and you would need administrator access to it. Then you could install some software into the protocol stack to track this.

    There is a huge legal minefield here. I suggest you talk to your system administrators for simpler solutions that are legal in your jurisdiction.


    What can be illegal about this? If of course he is not planning to put this software on some other computer without permission..


    Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
    Lester Burnham
    Rancher

    Joined: Oct 14, 2008
    Posts: 1337
    Elchin Asgarli wrote:What can be illegal about this?

    As Andrew said, it depends on the jurisdiction. There have been court decisions that port scanning a computer that is not under your control, or which you are explicitly allowed to probe, is considered an attack (and thus illegal).
    Elchin Asgarli
    Ranch Hand

    Joined: Mar 08, 2010
    Posts: 222

    Lester Burnham wrote:
    Elchin Asgarli wrote:What can be illegal about this?

    As Andrew said, it depends on the jurisdiction. There have been court decisions that port scanning a computer that is not under your control, or which you are explicitly allowed to probe, is considered an attack (and thus illegal).


    That makes sense.. Because Dashang was talking about getting packets before they reach destination and talking about wireshark, I thought he wants to do packet sniffing, which on his own machine should never be illegal.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: port scanning