Home > Back-end >  Java based on the CMD command: ipconfig for local default gateway
Java based on the CMD command: ipconfig for local default gateway

Time:09-28

 
/* *
* according to the CMD command: ipconfig;
* access to the local default gateway
* @ return
*/
Public static String getLocalGatewayByCmd () {
String localGateway="";//local gateway
List RunCommand=runCommand (" ipconfig ");//according to the CMD command to get the gateway
for(int i=0; IString [] vals=runCommand. Get (I). The split (" : ");
If (vals [0]. IndexOf (" gateway ")!=1 | |
Vals [0]. IndexOf (" gateway ")!=1 | |
Vals [0]. IndexOf (" Gateway ")!=1) {//intercept gateway based on the system language, obtain the value
LocalGateway=vals [1]. The trim ();
If (localGateway==null | |
LocalGateway. IsEmpty () | |
LocalGateway. Equals (" 127.0.0.1 ")) {
continue;
}
break;
}
}
Return localGateway;
}

CodePudding user response:

Availability, logic is ok
  • Related