00001 # Copyright (C) 2008-2009 Mark Hanegraaff 00002 # 00003 # This program is free software: you can redistribute it and/or modify 00004 # it under the terms of the GNU General Public License as published by 00005 # the Free Software Foundation, either version 3 of the License, or 00006 # (at your option) any later version. 00007 # 00008 # This program is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 # GNU General Public License for more details. 00012 # 00013 # You should have received a copy of the GNU General Public License 00014 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 00016 00017 from pcapyImplementation import pcapyImplementation 00018 from captureInterface import captureInterface 00019 from objects.logic.common.subjectInterface import subjectInterface 00020 00021 ## The one and only networkMonitor. 00022 # This class is not a singleton. It is just a global variable to the main application object. 00023 # The networkMonitor is both a subject and an observer. It's an observer of the pcapyImplementation class 00024 # which feeds it raw network data, and it is a subject in that there several other observers 00025 # that consume the same raw network data that this class receives. 00026 # 00027 # I debated having the captureInterface also act as a subjectInterface, and thus removing the need for a networkMontior class, 00028 # but I wanted to separate the two interfaces in the interest of re-usability. 00029 # 00030 # PcapyImplementation--data-->networkMonitor--data-->all_other_observers (storageManager, entityManager) 00031 # 00032 class networkMonitor(subjectInterface): 00033 def __init__(self): 00034 subjectInterface.__init__(self); 00035 self.networkIface = pcapyImplementation() 00036 self.networkIface.registerNotifyCallBack(self) 00037 00038 00039 00040 ## returns a list of all devices 00041 def getDeviceList(self): 00042 return self.networkIface.getDeviceList() 00043 00044 00045 00046 ## returns a dictionary of name/properties 00047 # @return Dictionary 00048 def getDeviceProperties(self): 00049 devList = self.getDeviceList() 00050 00051 retDict = dict() 00052 00053 # combine device name with its information 00054 for dev in devList: 00055 retDict[dev] = self.networkIface.queryDevice(dev) 00056 00057 return retDict 00058 00059 00060 00061 ## starts listening to a device 00062 # @param device String representing the device NPF name 00063 def startListening(self, device): 00064 self.networkIface.startListening(device) 00065 00066 00067 00068 ## Stops listening to a device 00069 def stopListening(self): 00070 self.networkIface.stopListening() 00071 00072 00073 ## This function is called whenever the captureInterface derived class 00074 # receives a new packet 00075 # @param header Raw DataLink header 00076 # @param data Raw DataLink frame 00077 # @param deviceName String representing NPF formatted Device Name 00078 def newPacketNotification(self, header, data, deviceName): 00079 self.notifyAll(header, data) 00080 #print header 00081
1.5.8