Posts

Showing posts from November, 2008

Build your own Network sniffer

Image
Recently, I ve been developing a tool to monitor the Network Traffic as an assignment. Here, I wish to share my experience with all of you who are interested in building your own Sniffer. Prerequisites : Java Programming capability, Knowledge on OOP(Object Oriented Programming) basics My Environment: I used the libraries specified for Java which is widely available. I ran my application on Windows XP only. But the libraries can be easily integrated with Linux based systems. I used NetBeans 6.1 version for development activities. But any other java IDE would do In setting up the environment, first you need to download Jpcap jar found at http://sourceforge.net/projects/jpcap Once you download this, you have to add this to your NetBeans project. It can be done as follows. After adding the Jar file to the project, you need to download the WinPCap driver. It can be easily downloaded from http://www.winpcap.org/ It is required to get low level networking access regarding packets. As for

Run a programme by java application

You may have encountered situations where you wish to run a programme say Web Browser (FireFox) from your Java programme. It is very simple Find the location of the actual executable of the programme. As in the case of FireFox Web Browser, the actual executable file is placed at C:\Program Files\Mozilla Firefox\firefox.exe You can use the following code to run it from your Java application Runtime runtime = Runtime.getRuntime(); runtime.exec("K:/Program Files/Mozilla Firefox/firefox.exe"); (YOU MUST USE A TRY CATCH BLOCK. Just excluded them for clarity) ENJOY programming :-) Here is a great tip if you wish to launch the native applications for specific tasks such as sending a mail, opening the native web browser. public static void main(String[] args) { Desktop dt = Desktop.getDesktop(); try { try { dt.browse(new URI("http://yahoo.com")); } catch (URISyntaxException ex) { Lo

Java Buffered Writer Issue

Using Buffered Writers is an efficient way to write the output to a file where hard disk accesses are costly. The main idea behind the Buffered Objects is(Here it is the buffered writer) having a buffer which is, writing the output to a memory location in the computer's main memory(which is faster than writing to hard disk). And then once the Buffer is filled with enough data, the whole buffer is written to the hard disk. However, this can bring up some issues which are difficult to find. One of such issues is my attempt to write to a text file using a buffered writer. I used the following code. FileWriter writer; BufferedWriter bWriter ; PrintWriter pwriter ; writer = new FileWriter (new File("./output. txt "); bWriter = new BufferedWriter (writer); pwriter =new PrintWriter ( bWriter ); int i=0; while(i<1000){ pwriter . println (i); i++;