Is there any sample code that can report the url that my PC is connecting with Java?
While I use my browser to connect to different sites and watch video online, it should capture the urls. Is it doable in Java?
I don’t want detailed traffic, just record the urls.
The fastest way is probably going to be to capture the output of the command-line
tsharkprogram (for at least windows and linux). This works on my linux box:And produces output like:
You should get something similar for Windows. Experiment. How you get the output of tshark into java is up to you.
If you want an all-java solution, how about http://jnetpcap.com/ ?
You’re going to have to write (or use a library that provides) some platform specific JNI code.
libpcap/WinPcap that jNetPcap uses provides this reliably on at least Windows and Linux from my experience. I have experience with libpcap/WinPcap but not with jNetPcap.
tsharkalso uses libpcap/WinPcap actually.Either way, you’re going to see very many false positives. Opening a HTML page requires getting many, many images, style sheets, javascript libraries etc. The snippet above is from opening a stackoverflow.com page.