-
February 6th, 2005, 11:56 AM
#11
Junior Member
I consider myself a complete noob when it comes to java.....
A couple minutes before finding this, I wrote this....doesn't it do the same thing?
Code:
import java.io.*;
import java.net.*;
public class PortScan {
public static void main(String[] args) throws IOException {
Socket j = new Socket();
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter outFile = new BufferedWriter(new FileWriter(new File("PortScan.txt")));
System.out.println("IP Address or Computer Name?");
String compname = input.readLine();
System.out.print("\nFrom: ");
String x1 = input.readLine();
int start = 0; int finish = 0;
System.out.print("\nTo: ");
String x2 = input.readLine();
try {
start = (Integer.parseInt(x1));
finish = (Integer.parseInt(x2));
}
catch(Exception gay1) {
System.out.println("Invalid Ports");
System.exit(1);
}
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, 04:57 PM
#12
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, 07:47 PM
#13
Member
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.
--BigDick
\"When in Rome, eat Rome!\" -Godzilla
-
February 8th, 2005, 03:39 PM
#14
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.
Cheers,
cgkanchi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|