Static VoidMain ()
{
Arraylist list = getalllocalmachines ();
For(IntI =0; I <list. Count; I ++)
{
Console. writeline (list [I]);
}
Console. readkey ();
}
// First, ping the host of the network segment cyclically.
// Next, use the following function to obtain the list of IP addresses with responses in all the LAN.
Public Static Arraylist getalllocalmachines ()
{
PROCESS p = New Process ();
P. startinfo. filename = " Cmd.exe " ;
P. startinfo. useshellexecute = False ;
P. startinfo. redirectstandardinput = True ;
P. startinfo. redirectstandardoutput = True ;
P. startinfo. redirectstandarderror =True ;
P. startinfo. createnowindow = True ;
P. Start (); p. standardinput. writeline ( " ARP- " );
P. standardinput. writeline ( " Exit " );
Arraylist list = New Arraylist ();
Streamreader reader = P. standardoutput;// Read IP address. Mac ....
String Iphead = DNS. gethostbyname (DNS. gethostname (). Addresslist [ 0 ]. Tostring (). substring ( 0 , 3 );
For ( String Line = reader. Readline (); line! = Null ; Line = reader. Readline ())
{
Line = line. Trim (); If (Line. startswith (iphead) & (line. indexof ( " Dynamic " )! =- 1 ))
{
String IP = line. substring ( 0 , 15 ). Trim (); String MAC = line. substring (line. indexof ( " - " )- 2 ,0x11 ). Trim ();
List. Add (IP );
}
}
Return List;
}