Atitit. obtain the network neighbor list java php c #. net python Atitit. obtain the network neighbor list java php c #. net python
1. get workgroup net view/domain 1
2. obtain the network neighbor list 1.
3. ping 1 to obtain the ip address of the machine.
4. Code 2
5. refer to 4
1. get workgroup net view/domain 2. get the network neighbor list
C: \ Users \ Administrator> net view server name annotation
---------------------------------------------------------------------
\ AT6T5TKUVHGT0IG
\ DY
\ GLEJSAZRY5YIIW0
\ USER-20151223FC
\ USER-20151225DJ
The command is successfully completed.
3. ping the ip address of the machine.
Author: Nickname: old Wow's Paw (full name: Attilax Akbar Al Rapanui Attila AKBA Arla Panui) Name: Ai long, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://www.cnblogs.com/attilax/
4. Code
Public static void main (String [] args ){
System. out. println (System. getProperty ("file. encoding "));
System. setProperty ("file. encoding", "gbk ");
System. out. println (System. getProperty ("file. encoding "));
List Li = Neighborhood. getNeighborhood ();
System. out. println (AtiJson. toJson (li ));
// System. out. println (neighborhood );
}
Private static List GetNeighborhood (){
List Li = Lists. newArrayList ();
String line = "";
Boolean begin = false;
String command = "net view ";
StringBuffer sb = new StringBuffer (); // variable length
Try {
Process process = Runtime. getRuntime (.exe c (command); // The Process instance can be used to control the Process and obtain relevant information.
// Each Java application has a Runtime class instance so that the application can be connected to the running environment.
// You can use the getRuntime method to obtain the current runtime. Exec (String) executes the specified String command in a separate process
BufferedReader br = new BufferedReader (new InputStreamReader (
Process. getInputStream (), "gbk "));
While (line = br. readLine ())! = Null ){
System. out. println (line );
Line = line. trim ();
// The name of your working group must be "Command completed successfully ." Or "The command completed successfully ."
If (line. endsWith ("Command completed successfully. ")
| Line. inclusignorecase ("The command completed successfully .")){
// Begin = false;
Break;
}
If (line. endsWith ("--------")){
Begin = true;
// Next ()
Continue;
}
If (begin ){
{
If (line. indexOf ("")! =-1) // if line contain empty char
Line = line. substring (2, line. indexOf (""));
Else
Line = line. substring (2, line. length ());
Li. add (line );
// Line = line + "" + getNeighborIP (line );
// Sb. append (""). append (line). append ("\ r \ n ");
// System. out. println ("get" + line );
}
}
}
Br. close ();
Process. waitFor (); // cause the current thread to wait. if necessary, wait until the Process indicated by the process object is terminated.
} Catch (IOException ioe ){
System. out. println (ioe );
} Catch (Exception e ){
System. out. println (e );
}
// String string = sb. toString ();
// Li. add (string );
Return li;
}
5. Reference
Use java to obtain the ip address and username of the network neighbor _ zhoujielunyzb _ Sina blog. htm