* RouterConfig constants
*/
private static final String STR_SSH_USERNAME_ROUTER = "root";
+ private static final String STR_SSH_USERNAME_RASPBERRYPI = "pi";
private static final String STR_SSH_USERNAME_HOST = "iotuser";
private static final String STR_POLICY_FILE_ALL = "_all";
private static final String STR_POLICY_FILE_EXT = ".policy";
+ private static final String STR_INCOMPLETE = "(incomplete)";
/**
* RouterConfig properties
}
/**
- * getAddressList() method gets list of IP addresses
+ * getAddressListTmp() method gets list of IP addresses from /tmp/dhcp.leases
* <p>
* This method sends an inquiry to the router to look for
* the list of DHCP leased addresses and their mapping to MAC
*
* @param strRouterAddress String that contains address of router
*/
- public void getAddressList(String strRouterAddress) {
+ public void getAddressListTmp(String strRouterAddress) {
//HashMap<String,String> hmMACToIPAdd = new HashMap<String,String>();
try {
}
}
+ /**
+ * getAddressListArp() method gets list of IP addresses from arp command
+ * <p>
+ * This method sends an inquiry to the router to look for
+ * the list of DHCP leased addresses and their mapping to MAC
+ * addresses
+ *
+ * @param strRouterAddress String that contains address of router
+ */
+ public void getAddressListArp(String strRouterAddress) {
+
+ //HashMap<String,String> hmMACToIPAdd = new HashMap<String,String>();
+ try {
+ // We replace with "cat /usr/sbin/arp"
+ String cmd = "ssh " + STR_SSH_USERNAME_RASPBERRYPI + "@" + strRouterAddress +
+ " /usr/sbin/arp";
+ Runtime runtime = Runtime.getRuntime();
+ Process process = runtime.exec(cmd);
+
+ InputStream inStream = process.getInputStream();
+ InputStreamReader isReader = new InputStreamReader(inStream);
+ BufferedReader bReader = new BufferedReader(isReader);
+ String strRead = null;
+ while((strRead = bReader.readLine()) != null){
+ String[] str = strRead.split("\\s+");
+ // Skip if "(incomplete)" is seen!
+ if (str[1].equals(STR_INCOMPLETE))
+ continue;
+ mapMACtoIPAdd.put(str[2], str[0]);
+ }
+ } catch (IOException ex) {
+ System.out.println("RouterConfig: IOException: " + ex.getMessage());
+ ex.printStackTrace();
+ }
+ }
+
/**
* getIPFromMACAddress() method gets IP from MAC address
*