System.out.println("Scanning...");
for(int x = start; x <= finish; x++) {
System.out.println("Checking Port " + x);
outFile.write("Port " + x + ":");
try {
j = new Socket(compname,x);
System.out.println("Port Open");
outFile.write(" Open");
outFile.newLine();
}
catch(Exception gay2) {
System.out.println("Port Closed");
outFile.write(" Closed");
outFile.newLine();
}
}
outFile.close();
System.out.println("\nScan Complete");
}
}
February 6th, 2005, 03:57 PM
cgkanchi
Yes, it does do the same thing. However, I'd recommend closing each Socket object like so...
Code:
for(int x = start; x <= finish; x++) {
System.out.println("Checking Port " + x);
outFile.write("Port " + x + ":");
try {
j = new Socket(compname,x);
System.out.println("Port Open");
outFile.write(" Open");
outFile.newLine();
j.close()
}
catch(Exception gay2) {
System.out.println("Port Closed");
outFile.write(" Closed");
outFile.newLine();
}
}
Otherwise, the sockets will remain open until the program closes.
Cheers,
cgkanchi
February 7th, 2005, 06:47 PM
BigDick
Just out of curiousity, how is the resource efficiency of this system? Java tends to be a resource whore, which is a small part of the reason I don't care for it. Also I noticed a comment about raw sockets, well, that's impossible in java, simply because of the platform independence that has become the hallmark of java. This, because of the JVM, makes it impossible to do something of this nature. To do that would totally remove the platform independent nature of java, making its inefficiency merely a hindrance.
February 8th, 2005, 02:39 PM
cgkanchi
I don't know how much memory an instance of this class takes, but since each socket is opened only when the previous one is closed, it's not very memory hungry. I just ran it to check, and it takes a little over 8 megs and almost no CPU when running on my Windows XP system. Also, about the raw socket support. If the person running it had jpcap and winpcap/libpcap installed on the system running it, raw sockets could still be used while keeping the program platform independent.