# Java Ping Program



## tech-it-^ (Aug 18, 2006)

Hey all! 

Recently, on some of my free time, I've been creating a simple program within java that can be used to read in a text file of IP addresses or host names and ping them and store them in an array the reply given from the ping process. 

For now, it is text, and is simply ran from the console. There aren't to many options right now. It can print all ping processes to console, print all reply's only (to console), send results to a txt file, and exit the program. Down the road I plan on putting a GUI on it and being able to enter in more commands such as nslookup capabilities, ability to tracert, and a lot more user options then I have now. 

There's one problem with my program though. IT TAKES FOREVER to run! Which is understandable given that I am just taking the runtime environment and sending the "ping" command to the appropriate process.

I heard something about threads. I read about them and it seems like it can solve my problem, but I'm not entirley sure how exactly to use them in my program. I'd like to disect the txt file and create multiple process instead of it always creating one process, pinging, closing, then creating the process again for the next IP, pinging, closing, etc... It'd be nice to have multiple processes running at the same time. Thing is, I'm not a java GURU by any means and the threading is kind of throwing me for a loop. So I was wondering if you guys could take a look at it, if you don't mind of course. 

The java files are attached, please keep in mind that all error handling has not been taken care of yet. That's because some stuff I don't know how to take care of-like if the text file started off at the top of the list with IP's then spaced down a few lines, and started IP's off again. Stuff like that. Please take a look and post all comments to my threading question here if you could. Everything should be attached, even an example txt file that has the proper format to enter IP's (called input) (file is ran from args). May have some formatting issues because of the IDE I used (netbeans) so it may look funky (Try opening it in notepad++). Oh, and its in a package so if you run it straight from cmd prompt, it'll throw an error at compilation. Just remove the package declaration. Thanks guys, I appreciate it.


----------



## tech-it-^ (Aug 18, 2006)

bump*


----------



## maretard (Dec 26, 2007)

http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html

That's a comprehensive Sun tutorial on how to use Threads and concurrency. 

Google is your friend :smooch:


----------



## tech-it-^ (Aug 18, 2006)

Alright, well I'm pretty sure I read over this already. I'll post questions. Thanks man.


----------

