Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to know that a particular ip is being accessed.

 
kamal krishna bhatt
Ranch Hand
Posts: 41
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to write an application which is running on a gateway and detect whether there is an access request for a particular ip address over any protocol.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's nice. So how are things going along with that?

OK, now seriously, do you have a question? Because I just read a notification that you are going to write a program.
 
kamal krishna bhatt
Ranch Hand
Posts: 41
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i want to know which API to use ,currently i am having a servlet which is listening to a particular url to be hit and then do whatever needed,but it is listening for http requests only if some body do ssh on that server then what should i do?
is there any other way of detection?
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To listen for SSH requests without creating a server socket on the SSH port (which you can't because there's already the SSH server running on it), you will probably need to interact with the network interface on a low level. Pure Java can't do that, so you'll either have to use JNI to write something yourself or use a third party library that has already implemented this. I think jpcap is a suitable library, but I haven't tested it myself.
 
kamal krishna bhatt
Ranch Hand
Posts: 41
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you !
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
kamal krishna bhatt
Ranch Hand
Posts: 41
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya that is true i cant create a socket on 22 port as ssh already running on that port but isn't it possible to redirect ssh request to another port where i can create socket process it here and the redirect it back to port22 ?
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write your own raw proxy. In short:
- create a ServerSocket on port 22
- upon an incoming connection, create a Socket to the SSH server (on a different port)
- copy all data from the incoming Socket to the SSH Socket and vice versa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic