Hallo,
ich habe ein programm geschrieben, mit welchem ich alle vergebenen IP-Adressen im Netzwerk auflisten will, was mir jedoch nur bedingt gelingt, unzwar gibt er erstens nicht wie gewünschte alle ping anfragen ein, dazu noch eine menge doppelt und nicht bis zum ende..
bin für jede Hilfe dankbar..
Code:
Hier der Nebenthread:
ich habe ein programm geschrieben, mit welchem ich alle vergebenen IP-Adressen im Netzwerk auflisten will, was mir jedoch nur bedingt gelingt, unzwar gibt er erstens nicht wie gewünschte alle ping anfragen ein, dazu noch eine menge doppelt und nicht bis zum ende..
bin für jede Hilfe dankbar..
Code:
Java:
package LAN_SCAN;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
public class scan
{
/* (c) by SkonroX */
public static Object[] e;
public static String hostip = null;
public static int port = 445;
public static Socket socket;
public static InetAddress host;
public static File file = new File( System.getProperty( "user.home" ) + "/desktop/IP-Liste.txt" );
public static File file2 = new File( System.getProperty( "user.home" ) + "/desktop/IP-Liste-Temp.txt" );
public static long roundTripTime;
public static BufferedWriter bw = null;
public static BufferedWriter bw2 = null;
public static int zaehler;
private static scaning[] sc = null;
public static String klasse = "c";
public static void main( String[] args )
{
if( klasse == "a" )
{
try { classa(); }
catch ( IOException e ) { e.printStackTrace(); }
}
if( klasse == "b" )
{
try { classb(); }
catch ( IOException e ) { e.printStackTrace(); }
}
if( klasse == "c" )
{
try { classc(); }
catch ( IOException e ) { e.printStackTrace(); }
catch ( InterruptedException e ) { e.printStackTrace(); }
}
if( klasse != "a" && klasse != "b" && klasse != "c" ) { System.out.println( "Ungültige Eingabe!" ); }
}
private static void classc() throws IOException, InterruptedException
{
zaehler = 0;
int j = 0;
sc = new scaning[ ( 256 * 256) + 1 ];
bw = new BufferedWriter( new FileWriter( file ) );
bw2 = new BufferedWriter( new FileWriter( file2 ) );
bw.write( "IP-Adress finder for network class C (c) by SkonroX" );
bw2.write( "IP-Adress with failure connection:" );
bw.newLine();
bw2.newLine();
bw.flush();
bw2.flush();
for( int i = 0; i < 256; i++ )
{
hostip = "192.168." + j + "." + i;
/*if( zaehler == 500 )
{
if( !sc[ 499 ].isAlive() ) { zaehler = 0; i--; }
else { i--; }
}*/
//if( zaehler != 500 )
//{
sc[ zaehler ] = new scaning();
sc[ zaehler ].main( hostip, port );
sc[ zaehler ].start();
zaehler++;
if( i == 255 && j < 256 ) { j++; i = 0; }
if( j > 255) { break; }
//}
}
bw.close();
bw2.close();
}
private static void classb() throws IOException
{
int j = 0, k = 0, zaehler = 0;
scaning[] sc = new scaning[ ( ( 255 * 255 ) * 255 ) + 1 ];
bw = new BufferedWriter( new FileWriter( file ) );
bw.write( "IP-Adressen finder for network class B (c) by SkonroX" );
bw.newLine();
bw.flush();
for( int i = 0; i < 256; i++ )
{
hostip = "172." + k + "." + j + "." + i;
sc[ zaehler ] = new scaning();
sc[ zaehler ].start();
zaehler++;
if( i == 255 ) { j++; i = 0; }
if( j == 255 && i == 255 ) { k++; i = 0; j = 0; }
if( j > 255 || k > 255) { break; }
}
bw.close();
}
private static void classa() throws IOException
{
int j = 0, k = 0, l = 0, zaehler = 0;
scaning[] sc = new scaning[ ( ( ( 255 * 255 ) * 255 ) * 255 ) + 1 ];
bw = new BufferedWriter( new FileWriter( file ) );
bw.write( "IP-Adressen finder for network class A (c) by SkonroX" );
bw.newLine();
bw.flush();
for( int i = 0; i < 256; i++ )
{
hostip = l + "." + k + "." + j + "." + i;
sc[ zaehler ] = new scaning();
sc[ zaehler ].start();
zaehler++;
if( i == 255 ) { j++; i = 0; }
if( j == 255 && i == 255 ) { k++; i = 0; j = 0; }
if( k == 255 && j == 255 && i == 255 ) { l++; i = 0; j = 0; k = 0; }
if( j > 255 || k > 255 || l > 255) { break; }
}
bw.close();
}
}
Hier der Nebenthread:
Java:
package LAN_SCAN;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
public class scaning extends Thread
{
private static Object[] e;
private static long roundTripTime;
private static InetAddress host;
private static Socket socket;
private static String wert1;
private static int wert2;
public static void ping( String hostip, int string )
{
try
{
roundTripTime = System.nanoTime();
host = InetAddress.getByName( hostip );
socket = new Socket( host, string );
roundTripTime = ( System.nanoTime() - roundTripTime ) / 1000000L;
socket.close();
e = new Object[]{ host.getHostAddress(), host.getHostName(), roundTripTime };
System.out.println( "HostIP: " + e[ 0 ] + " " + "HostName: " + e[ 1 ] + " " + "MilliSeconds: " + e[ 2 ] );
scan.bw.write( "HostIP: " + e[ 0 ] + " " + "HostName: " + e[ 1 ] + " " + "MilliSeconds: " + e[ 2 ] );
scan.bw.newLine();
scan.bw.flush();
}
catch( Exception e )
{
System.out.println( e.getMessage() + " when ping IP: " + hostip );
try
{
scan.bw2.write( e.getMessage() + " when ping IP: " + hostip );
scan.bw2.newLine();
scan.bw2.flush();
}
catch (IOException e1) { e1.printStackTrace(); }
}
}
public void run()
{
ping( wert1, wert2 );
}
public void main( String a, int x )
{
wert1 = a;
wert2 = x;
return;
}
}