Advertisement
moonlightcheese

subnet

Oct 18th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1.         protected Void doInBackground(Void... voids) {
  2.             String subnetString = null;
  3.             String subnetPrefixString = null;
  4.             final List<String> serverList = new ArrayList<String>();
  5.  
  6.             try {
  7.                 // Get the IP address string
  8.                 subnetString = InetAddress.getLocalHost().toString();
  9.                 subnetString = subnetString.substring(subnetString.indexOf("/") + 1);
  10.                 subnetPrefixString = subnetString.substring(0, subnetString.lastIndexOf(".")) + ".";
  11.             } catch (UnknownHostException e) {
  12.                 // Exception output
  13.             }
  14.  
  15.             for(int i=1; i<255; i++) {
  16.                 final String ipString = subnetPrefixString + String.valueOf(i);
  17.                 final Runnable sniffRunnable = new Runnable() {
  18.                     public void run() {
  19.                         Bundle b = new Bundle();
  20.                         Message m = new Message();
  21.                         try {
  22.                             serverList.add(find(ipString));
  23.                         } catch (IOException e) {
  24.                             b.putString("error", e.getMessage());
  25.                             //b.putString("error", "error: "+e.toString());
  26.                         }
  27.                         b.putString("valid", ipString);
  28.                         m.setData(b);
  29.                         //addressHandler.sendMessage(m);
  30.                     }
  31.                 };
  32.                 new Thread(sniffRunnable).start();
  33.             }
  34.  
  35.             return voids[0];
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement