From: <an...@us...> - 2008-01-28 14:01:48
|
Revision: 719 http://magicmap.svn.sourceforge.net/magicmap/?rev=719&view=rev Author: anweiss Date: 2008-01-28 05:22:14 -0800 (Mon, 28 Jan 2008) Log Message: ----------- added hashmap with attributes for every node that can be stored on the server Added Paths: ----------- trunk/magicmapclient/src/net/sf/magicmap/client/net/VistaNetworkInfo.java trunk/magicmapclient/src/net/sf/magicmap/client/utils/NodeTypes.java Added: trunk/magicmapclient/src/net/sf/magicmap/client/net/VistaNetworkInfo.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/net/VistaNetworkInfo.java (rev 0) +++ trunk/magicmapclient/src/net/sf/magicmap/client/net/VistaNetworkInfo.java 2008-01-28 13:22:14 UTC (rev 719) @@ -0,0 +1,102 @@ +/* + * Created on 21.01.2008 + */ + +package net.sf.magicmap.client.net; + +import java.io.IOException; +import java.text.ParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class VistaNetworkInfo extends NetworkInfo { + + public static final String IPCONFIG_COMMAND = "netsh wlan show interfaces"; + + @Override + public String parseMacAddress() throws ParseException{ + // run command + String ipConfigResponse = null; + try { + ipConfigResponse = runConsoleCommand(VistaNetworkInfo.IPCONFIG_COMMAND); + } catch (IOException e) { + e.printStackTrace(); + throw new ParseException(e.getMessage(), 0); + } + + java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(ipConfigResponse, "\n"); + String lastMacAddress = null; + while (tokenizer.hasMoreTokens()) { + String line = tokenizer.nextToken().trim(); + + if (line.trim().startsWith("Status")) { + String[] splitString = line.split(":"); + return lastMacAddress; + } + // see if line might contain a MAC address + int macAddressPosition = line.indexOf(":"); + if (macAddressPosition <= 0) continue; + + // trim the line and see if it matches the pattern + String macAddressCandidate = line.substring(macAddressPosition + 1).trim(); + if (VistaNetworkInfo.isMacAddress(macAddressCandidate)) { + lastMacAddress = macAddressCandidate; + continue; + } + } + + ParseException ex = new ParseException("No active connection found or cannot read MAC address from [" + + ipConfigResponse + "]", 0); + ex.printStackTrace(); + throw ex; + } + + @Override + public void collectMacAddresses() throws ParseException{ + NetworkInfo.macAddresses.clear(); + // run command + String ipConfigResponse = null; + try { + ipConfigResponse = runConsoleCommand(VistaNetworkInfo.IPCONFIG_COMMAND); + } catch (IOException e) { + e.printStackTrace(); + throw new ParseException(e.getMessage(), 0); + } + + java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(ipConfigResponse, "\n"); + String macAddressCandidate; + String lastMAC = null; + String[] splitLine = null; + boolean foundActive = false; + while (tokenizer.hasMoreTokens()) { + // split the line and take everything right from the ":" + splitLine = tokenizer.nextToken().trim().split(":"); + macAddressCandidate = splitLine[1]; + // see if line might contain a MAC address + if (VistaNetworkInfo.isMacAddress(macAddressCandidate)) { + // Ok we got something, but we better check if it's active + macAddressCandidate.replace(':', '-'); + lastMAC = macAddressCandidate; + } else if ((lastMAC != null) && (splitLine[0].trim().equals("Status"))) { + // only german to test things + if (!splitLine[1].equals("getrennt")) { + NetworkInfo.macAddresses.add(lastMAC); + foundActive = true; + break; + } + } + } + // we found some wireless devices but none was active + if ((lastMAC != null) && !foundActive){ + NetworkInfo.macAddresses.add(lastMAC); + System.out.println("Inaktives Netz"); + } + } + + private static boolean isMacAddress(String macAddressCandidate){ + Pattern macPattern = Pattern.compile("([0-9A-F]{2})(([-:][0-9A-F]{2}){5})(([-:][0-9A-F]{2}){2})?"); + // .compile("[0-9a-fA-F]{2}([-:]{1}[0-9a-fA-F]{2}[-:]{1}[0-9a-fA-F]{2}[-:]{1}[0-9a-fA-F]{2}[-:]{1}[0-9a-fA-F]{2}[-:]{1}[0-9a-fA-F]{2})"); + Matcher m = macPattern.matcher(macAddressCandidate.toUpperCase()); + return m.matches(); + } +} \ No newline at end of file Added: trunk/magicmapclient/src/net/sf/magicmap/client/utils/NodeTypes.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/utils/NodeTypes.java (rev 0) +++ trunk/magicmapclient/src/net/sf/magicmap/client/utils/NodeTypes.java 2008-01-28 13:22:14 UTC (rev 719) @@ -0,0 +1,9 @@ +package net.sf.magicmap.client.utils; + + +public final class NodeTypes { + public static final String ACCESSPOINT = "ACCESSPOINT"; + public final static String LOCATION = "POSITION"; + public static final String CLIENT = "CLIENT"; + public static final String SNIFFER = "SNIFFER"; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |