Wednesday, September 5, 2007

A very nice trick of java..

We dont know how to create a program for ping like networking tool..
but we know that windows uses it.. and its own it... So its a trick to
use any service/tool of the windows or any operating system..

Java
Runtime can execute any tool for us.. and we can get input stream and
output stream of that tool.. so I think if u are a java programmar; u
got my poin..

here is an example of this..

DefaultListModel model = new DefaultListModel();
Runtime r = Runtime.getRuntime();
try {
InputStream i = r.exec("tasklist /v").getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(i));

String str = br.readLine();
while(br.readLine()!=null){
model.addElement(str);
str = br.readLine();
}
} catch (IOException ex) {
ex.printStackTrace();
}

this shows a complete list of running tasks on our computer...

so
if we know a specific tool that is used for desired purpose like
ping... use ping to be run and get input stream and then u have created
a program like ipscanner or a ping utility for any platform...

also i think that the same concept can be used in any language..

enjoy the tricks

--Ravi Kumar Gupta
http://blogs.ibibo.com/techd
http://techdc.blogspot.com/
http://blogsense.iblogger.org/lnmiit.ravi
http://lnmiit.blogspot.com/

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.