aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes how to implement an app in a bridge to grab input stream from the Internet Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "how to implement an app in a bridge to grab input stream from the Internet" Watch "how to implement an app in a bridge to grab input stream from the Internet" New topic
Author

how to implement an app in a bridge to grab input stream from the Internet

qq beng
Greenhorn

Joined: Apr 17, 2005
Posts: 2
I set up a pc as a linux-based (Red Hat 9.0) bridge device at first. The pc got two NICs, both of their IPs set as 0.0.0.0. Just now, whole the LAN can uses the pc as a transparent bridge to communicate with external network without change any network setting.

Consider to monitor the data stream between LAN and external network. I try to implement a sniffer-like app in the bridge device now.

Below is a portion of my sniffer app, as I run the app in the bridge device, the outcoming result will be:
print test line 01

not my expected result:
print test line 01
print test line 02

Can anyone help me to clear my idea?

public grabInputStream()
{
String t = "";

int listenPort = 80;

try
{
ServerSocket serverSocket = new ServerSocket(listenPort);

System.out.println("print test line 01");

Socket listenSocket = serverSocket.accept();

System.out.println("print test line 02");

InputSream listenInputStream = listenSocket.getInputStream();

while (listenInputStream.available()>0)
{
t+=(char)listenInputStream.read();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8263

No one is making requests of 0.0.0.0:80, where you are listening. The requests are being forwarded by the linux kernel to the appropriate hosts. Since forwarding takes place at the kernel level you'd probably have to put hooks in the kernel to let you monitor traffic or do some iptables magic to route requests to some port locally which you could monitor, then forward that traffic on to it's destination.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
qq beng
Greenhorn

Joined: Apr 17, 2005
Posts: 2
Thank you, Joe Ess. You really made clear for me now, thanks for your instruction & suggestion. I will do more research about the kernel level and "to put hooks in the kernel". I appreciated to hear more reference or information from you if you are in convenience, thanks
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to implement an app in a bridge to grab input stream from the Internet
 
Similar Threads
How to fix this??
Redirecting Proxy Server request...
How to test network function?
IE - Java app communication
MIDP and Connection Not Found Exception: