def setSandbox(self): sandbox = {} sandbox["blockchain"] = _global.get("blockchain") sandbox["node"] = _global.get("node") sandbox["dt"] = self.dt() sandbox["http"] = self.http self.sandbox = sandbox
def mac(): #初始化 deviceTable = gl.get('deviceTable') ipPrefix = gl.get('ipPrefix') ipRange = gl.get('ipRange') content = ('', '') #邮件正文 macData_sensitive = deviceTable['sensitive'].keys() macData_insensitive = deviceTable['insensitive'].keys() #查询 g = __IP2MAC() macList = [] nFailure = 0 for i in range(ipRange[0], ipRange[1]): ip = ipPrefix + '.' + str(i) #当前ip nloop = 10 #循环次数 while nloop > 0: #若检测ipRange中的地址失败,则循环检测 mac = g.getMac(ip) nloop -= 1 if mac != '00-00-00-00-00-00': macList.append(mac.upper()) break nFailure = 0 if (nloop != 0) else nFailure + 1 if nFailure > 10: #如果连续10个ip查询失败则直接停止查询 break #查询 version2 ''' g = __IP2MAC_v2() macList = g.getMacList() ''' #返回结果 content_sensitive = '' content_insensitive = '' for mac in macList: if mac in macData_sensitive: content_sensitive += (mac + ' ' + deviceTable['sensitive'][mac] + '\n') elif mac in macData_insensitive: content_insensitive += (mac + ' ' + deviceTable['insensitive'][mac] + '\n') else: content_insensitive += (mac + '\n') #content = (content_sensitive, content_insensitive) content = content_sensitive + content_insensitive return content, macList
def sending(message): #初始化 msg_from = gl.get('msg_from') lic_code = gl.get('lic_code') msg_to = gl.get('msg_to') subject = gl.get('subject') content = __getContent(message) #开始发送 _msg_to = [recevier for recevier in msg_to if recevier != ''] for recevier in _msg_to: success = __sending_to_a_receiver(msg_from, lic_code, recevier, subject, content) if not success: print(recevier + ': 邮件发送失败')
def getWordEntrys(word): voca_model = globalVar.get('voca_model') value = [] for ind in range(len(voca_model)): if word == voca_model[ind]['word']: value = [voca_model[ind]] return value
def __init__(self,name): UTXO.logger = logger.logger UTXO.database = _global.get("database") # {3a75be...:[{"index":0,"txout":TXout1},{"index":1,"txout":TXout2}], # m09qf3...:[{"index":0,"txout":TXout3}]} self.utxoSet={} self.name = name
def insertVocabulary(word, startVector): assert type(startVector) == np.ndarray # startVector = [round(v, 5) for v in startVector] # startStr = json.dumps(startVector) voca_model = globalVar.get('voca_model') insert_id = len(voca_model) - 1 voca_model.append({'word': word, 'vector': startVector, 'id': insert_id}) return insert_id
def flag(macList_now,hourAndMinute_now,sendflag_last): #参数初始化 QueryInterval = gl.get('QueryInterval') deviceTable = gl.get('deviceTable') TimeTable = gl.get('TimeTable') RuleTable = gl.get('RuleTable') recordFilePath = gl.get('recordFilePath') sendFlag = False #输出:是否执行发送操作 #开始运行 macData_sensitive = deviceTable['sensitive'].keys() isOnline_now = inTheList(macData_sensitive, macList_now) #当前是否在 #hourAndMinute_now = timeString.get('%H%M') #当前的小时和分钟 hm_now = int(hourAndMinute_now) timeString_now = timeString.get('%Y%m%d') #当前的年月日 timeString_old,onlineRecords = readRecordsFile(recordFilePath) #在线记录和时间戳 #基于时间表的发送判断 if len(TimeTable)>0 and timeString.getDayOfWeek() not in [5,6]: recentMomentList = [hm_now-time for time in TimeTable if hm_now>=time] if len(recentMomentList) != 0: recentMoment = min(recentMomentList) #若上一次没有发送,且时间间隔(minute)小于查询间隔 if not sendflag_last and recentMoment <= QueryInterval: sendFlag = True #基于规则表的发送判断 if not sendFlag: if len(onlineRecords)==0: #上一次的records.txt为空 sendFlag = actionWithoutRecords() else: #上一次的records.txt不为空 if timeString_now != timeString_old: #不是同一天 sendFlag = actionWithoutRecords() else: #若记录和当前值属于同一天,则判断敏感人物的在线情况 sendFlag = actionWithRecords(hm_now,isOnline_now,onlineRecords,RuleTable) #更新records.txt if len(onlineRecords)==0 or (timeString_now!=timeString_old): #records.txt为空或者上次的不是同一天 writeRecordsFile(recordFilePath,hourAndMinute_now,isOnline_now) #重新记录 else: #上一次的records.txt不为空 writeRecordsFile(recordFilePath,hourAndMinute_now,isOnline_now,onlineRecords) #更新记录 record = hourAndMinute_now+' '+str(isOnline_now)+'\n' return sendFlag,record
def saveJson(): voca_model = globalVar.get('voca_model') # 0.3 的效果不好 for i in range(len(voca_model)): voca_model[i]['vector'] = voca_model[i]['vector'].tolist() # voca_model = {'test': 'testValue'} # 存放读取的数据 with open("./data.json", 'w', encoding='utf-8') as json_file: json.dump(voca_model, json_file, ensure_ascii=False) for i in range(len(voca_model)): voca_model[i]['vector'] = np.array(voca_model[i]['vector'])
def update_o_grad(entry, grad): # print('entry') # print(type(entry['vector'])) # print(entry['vector']) assert type(entry['vector']) == np.ndarray step = globalVar.get('step') # vec = np.array(entry['vector']) vec = entry['vector'] zeroArr = np.zeros(int(len(vec) / 2)) vec_grad = np.concatenate((zeroArr, np.array(grad)), axis=0) return vec - vec_grad * step
def getNegSameples(contextWords, k=10): voca_model = globalVar.get('voca_model') num = len(voca_model) - 1 if num <= 0: return [] # voca_model = globalVar.get('voca_model') values = [] for index in range(50): randomEntry = voca_model[np.random.randint(num)] assert type(randomEntry['vector']) == np.ndarray values.append(randomEntry) return values
def __init__(self, dictionary): Block.logger = logger.logger Block.database = _global.get("database") utils.dictConvert(dictionary, self, BLOCK_VAR_CONVERSIONS) data = [] if hasattr(self, 'data'): for item in self.data: data.append(Transaction.parseTransaction(item)) self.data = data if not hasattr(self, 'diffcult'): self.diffcult = 0 if not hasattr(self, 'nonce'): #we're throwin this in for generation self.nonce = 0 if not hasattr( self, 'hash' ): #in creating the first block, needs to be removed in future self.hash = self.updateHash()
def findWord(word, length=10): entrys = voca_model.getWordEntrys(word) if len(entrys) == 0: print('没找到') cen_entry = entrys[0] vocabulary = globalVar.get('vocabulary') allEntrys = vocabulary unsortedList = [] for et in allEntrys: deviationArr = cen_entry['vector'] - et['vector'] # deviationArr = np.fabs(deviationArr) deviationArr = [round(de, 5) for de in deviationArr.tolist()] deviationArr = np.square(np.array(deviationArr)) deviation = np.sum(deviationArr) unsortedList.append({'deviation': deviation, 'id': et['id']}) sortedList = sorted(unsortedList, key=lambda dic: dic['deviation']) for nearId in sortedList[0:length]: print(voca_model.getWordById(nearId['id'])['word'])
def getWordById(entryId): voca_model = globalVar.get('voca_model') return voca_model[entryId]
def update_i_grad(entry, grad): step = globalVar.get('step') vec = entry['vector'] zeroArr = np.zeros(int(len(vec) / 2)) vec_grad = np.concatenate((np.array(grad), zeroArr), axis=0) return vec - vec_grad * step
功能说明: - 可以实现局域网设备在线情况的查询,并通过邮件通知 - 基本原理为, 搜索局域网内的设定网段的ip,通过ARP协议获取mac地址, 经过是否通知的判断后,通过QQ邮箱向用户发送设备在线情况 """ import mailSender import macQueryServer import sendManager import timeString import globalVar as gl if __name__ == '__main__': #变量初始化 gl.init() QueryInterval = gl.get('QueryInterval') DurationOfSleep = gl.get('DurationOfSleep') # 循环检测 sendflag_last = False MessageList = [''] while True: # 查询局域网内的设备 content, macList = macQueryServer.mac() # 邮件正文 hourAndMin_now = timeString.get('%H%M') #当前时间 fullMessage = hourAndMin_now + ':\n' + content print(fullMessage) # 基于判断准则获取是否发送的标志
def update_vec(entry, vec): # entry 直接传这个词所在的index assert type(vec) == np.ndarray voca_model = globalVar.get('voca_model') voca_model[entry['id']]['vector'] = vec
def __init__(self): # 获取本机IP地址 self.host = gethostbyname(gethostname()) self.currentDir = gl.get('currentDir')
def __init__(self, blocks): Chain.logger = logger.logger _global.set("blockchain",self) Chain.database = _global.get("database") self.blocks = blocks self.utxo = UTXO('main')
def __init__(self, name=None): Wallet.logger = logger.logger Wallet.database = _global.get("database") if name: self.chooseByName(name)