001: import javax.swing.*;
002:
003:
004:
005:
006:
007:
008:
009: public class ScanIPRange implements Constants{
010: private String ip_range_beginning;
011: private String ip_range_end;
012: private int loop_count;
013:
014:
015:
016:
017:
018:
019:
020:
021: public ScanIPRange(String ip_range_beginning,
022: String ip_range_end)
023: {
024: this.ip_range_beginning = ip_range_beginning;
025: this.ip_range_end = ip_range_end;
026: loop_count = BasicIPTools.get_required_host_count(
027: this.ip_range_beginning,this.ip_range_end);
028: calculate_required_loop();
029: }
030:
031:
032:
033:
034:
035: public static void main(String arg[]) throws InterruptedException {
036: String first_ip = JOptionPane.showInputDialog("IP araligin ilk degerini girin:");
037: String last_ip = JOptionPane.showInputDialog("IP araligin son degerini girin");
038:
039:
040: Timer t = new Timer();
041: t.start();
042: ScanIPRange a = new ScanIPRange(first_ip,last_ip);
043: a.start_scan();
044: t.end();
045: System.out.println("\n\n**************************");
046: System.out.println("TOPLAM TARANAN ARALIK: "+first_ip+" - "+last_ip);
047: System.out.println("Harcanan Zaman:\t" + t.duration()+" (ms)");
048: System.out.println("**************************");
049: }
050:
051:
052:
053:
054:
055:
056: public void start_scan() throws InterruptedException {
057: int i=0;
058: String start_ip,stop_ip;
059: start_ip = ip_range_beginning;
060: stop_ip = BasicIPTools.increase_IP(start_ip,MAX_THREAD_COUNT);
061: while( i < loop_count ) {
062: if( !if_exceeds(start_ip,ip_range_end,MAX_THREAD_COUNT) ) {
063: PingSweepStart sweep = new PingSweepStart(start_ip,stop_ip);
064: sweep.start();
065: sweep.join();
066: sweep = null;
067:
068: stop_ip = BasicIPTools.increase_IP(stop_ip);
069: start_ip = stop_ip;
070: stop_ip = BasicIPTools.increase_IP(stop_ip,MAX_THREAD_COUNT);
071: i++;
072: }
073: else {
074: PingSweepStart sweep = new PingSweepStart(start_ip,ip_range_end);
075: sweep.start();
076: sweep.join();
077: sweep = null;
078:
079: break;
080: }
081: System.gc();
082: }
083: }
084:
085:
086:
087:
088:
089:
090:
091:
092:
093:
094: private boolean if_exceeds(String start_ip, String end_ip,
095: int Step)
096: {
097: String after_addition =
098: BasicIPTools.increase_IP(start_ip,Step);
099: if( after_addition.equals(
100: BasicIPTools.find_greater_address(
101: after_addition,end_ip)))
102: return true;
103: return false;
104: }
105:
106:
107:
108:
109:
110: private void calculate_required_loop()
111: {
112: if( loop_count%MAX_THREAD_COUNT!=0 ) {
113: loop_count /= MAX_THREAD_COUNT;
114: loop_count++;
115: }
116: else
117: loop_count /= MAX_THREAD_COUNT;
118: }
119: }
120: