Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void getIPInformation() {
- try {
- Pattern ipAddressPattern = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
- Process ipconfig = Runtime.getRuntime().exec("ipconfig");
- BufferedReader in = new BufferedReader(new InputStreamReader(ipconfig.getInputStream()));
- String s = null;
- while((s = in.readLine()) != null) {
- Matcher m = ipAddressPattern.matcher(s);
- if(m.find()) {
- String ip = m.group();
- if(s.toLowerCase().contains("gateway")) {
- defaultGateway = ip;
- } else if(s.toLowerCase().contains("ip") && s.toLowerCase().contains("address")) {
- ipAddress = ip;
- }
- }
- System.out.println(s);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(defaultGateway == null) {
- System.out.println("Could not find default gateway.");
- }
- if(ipAddress == null) {
- System.out.println("Could not find IPv4 address.");
- }
- }
Add Comment
Please, Sign In to add comment