def set_ap(self): from socket import access_points, access_point, select_access_point, set_default_access_point apid = [k for k in self.aps if k['name'] == u'WAP over GPRS'] if apid: #找的默认的接入点 self.apid = apid[0] self.ap = access_point(self.apid['iapid']) self.setting[6] = unicode(self.aps.index(self.apid)) set_default_access_point(self.ap) else: #没找到就选一个 self.apid_i = select_access_point() self.apid = [k for k in self.aps if k['iapid'] == self.apid_i][0] self.ap = access_point(self.apid['iapid']) self.setting[6] = unicode(self.aps.index(self.apid)) set_default_access_point(self.ap)
def set_accesspoint(): global _SETTINGS_ACCESPOINT apid = socket.select_access_point() if appuifw.query(u"Set as default access point", "query") == True: set_setting(_SETTINGS_ACCESPOINT, repr(apid)) apo = socket.access_point(apid) socket.set_default_access_point(apo)
def set_ap(): apid = config.get("internet","apid",None) if apid == None: socket.set_default_access_point(None) else: ap = socket.access_point(apid) socket.set_default_access_point(ap)
def _acionaModalidade(self, tamanho): #importando as bibliotecas sys.path.append(PATHLIB) import logica self._logica = logica.Logica(tamanho) if (self.modalidade == COMPUTER): import jogador self.computador = jogador.Inteligencia() elif (self.modalidade == IMPOSSIBLE): import jogador self.computador = jogador.Inteligencia(IMPOSSIBLE, self._logica.tabuleiro()) self.modalidade = COMPUTER elif (self.modalidade == REMOTE): INTERNET = 0 BLUETOOTH = 1 import aserver if (self.conexao == INTERNET): ap_id = socket.select_access_point() apo = socket.access_point(ap_id) apo.start() ip = apo.ip() self.servidor = aserver.Servidor(ip) appuifw.query(u"Mostre o IP ao seu amigo: " + str (ip), 'info') elif (self.conexao == BLUETOOTH): self.servidor = aserver.BTSender() self.servidor.conectar(self._logica.tabuleiro())
def _select_access_point(self, apid = None): """ Shortcut for socket.select_access_point() TODO: save selected access point to the config TODO: allow user to change access point later """ if apid is not None: self.apid = apid else: access_points = socket.access_points() sort_key = "iapid" decorated = [(dict_[sort_key], dict_) for dict_ in access_points] decorated.sort() access_points = [dict_ for (key, dict_) in decorated] ap_names = [dict_["name"] for dict_ in access_points] ap_ids = [dict_["iapid"] for dict_ in access_points] selected = appuifw.selection_list(ap_names, search_field=1) #print selected, ap_names[selected], ap_ids[selected] if selected is not None: self.apid = ap_ids[selected] if self.apid: self.apo = socket.access_point(self.apid) socket.set_default_access_point(self.apo) self.config["apid"] = self.apid self.save_config() self._update_menu() return self.apid
def ap(): #print "set default access- point" #print config["ap"] ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo) config["ap"] = ap_id save_config()
def get_accesspoint(self): config = self.get_config() if not config.get('apid') == None : apid = config.get('apid') apo = socket.access_point(apid) socket.set_default_access_point(apo) else: self.set_accesspoint()
def get_accespoint(): global _SETTINGS_ACCESPOINT apid = get_setting(_SETTINGS_ACCESPOINT) if not apid == None: apo = socket.access_point(int(apid)) socket.set_default_access_point(apo) else: set_accesspoint()
def set_accesspoint(self): apid = socket.select_access_point() if appuifw.query(u"Set as default access point","query") == True: appuifw.note(u"Saved default access point ", "info") config = self.get_config() config['apid'] = apid self.save_config(config) apo = socket.access_point(apid) socket.set_default_access_point(apo)
def set_accesspoint(): apid = socket.select_access_point() if appuifw.query(u"Set as default access point", "query") == True: f = open('e:\\apid.txt', 'w') f.write(repr(apid)) f.close() appuifw.note(u"Saved default access point ", "info") apo = socket.access_point(apid) socket.set_default_access_point(apo)
def __init__(self, servport = NETBIOS_NS_PORT, apn=None): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if not apn: apn = socket.select_access_point() e32.ao_yield() if not apn: raise NetBIOSError, 'Please select a AP' ap = socket.access_point(apn) socket.set_default_access_point(ap) ap.start()
def ok(): try: file = open('e:\\system\\apps\\geturl\\set.ini', 'r') poin = file.read() file.close() socket.set_default_access_point(socket.access_point(int(poin))) except: pass url = text.get() urln = urllib.urlopen(url) ur = urln.geturl() text.set(ru(ur))
def start(self): try: self.apid = socket.select_access_point() self.ap = socket.access_point(self.apid) socket.set_default_access_point(self.ap) id = appuifw.query(u'DOUGA-ID', 'text') if not id: self.exit() download(unicode(id).encode('utf-8')) except Exception, e: traceback.print_exc()
def __init__(self, inet_mode): self.server_host = "http://test.talking-points.org" self.inet_mode = inet_mode self.mac_tpid_mapping = {'00194fa4e262': 33, '000272c008cb': 31, '0010c65e9224': 34} if self.inet_mode == "online": ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo) # make sure path exists if e32.in_emulator(): self.dir = u"c:\\python\\tp_offline" else: self.dir = u"e:\\python\\tp_offline" if not os.path.exists(self.dir): os.makedirs(self.dir)
def start(self): if self._access_point_started: return if not self._default_access_point: confirm = appuifw.query(u"This operation requires data transfer. Confirm?", 'query') if not confirm: return apid = socket.select_access_point() # pylint: disable-msg=E1101 if not apid: return self._default_access_point = socket.access_point(apid) # pylint: disable-msg=E1101 socket.set_default_access_point(self._default_access_point) # pylint: disable-msg=E1101 self._default_access_point.start() self._access_point_started = True
def restoreSettings(self): try: f = open("c:\\translate.cfg") self.source, self.target, accessPointId = f.read().split(",") f.close() self.accessPointId = int(accessPointId) except: self.source = "en" self.target = "da" self.accessPointId = "" try: self.accessPoint = socket.access_point(self.accessPointId) socket.set_default_access_point(self.accessPoint) except: pass
def RetrieveAccessPointSelection(): if os.path.exists(apidFile): print "ap file exist" file = open(apidFile,'r') apid = sel_access_point(int(file.read())) file.close else: print "no stored iap. will prompt." apid = sel_access_point(0) StoreAccessPointSelection(apid) if apid: apo = socket.access_point(apid) socket.set_default_access_point(apo) return apo else: return None
def RetrieveAccessPointSelection(): if os.path.exists(apidFile): print "ap file exist" file = open(apidFile, 'r') apid = sel_access_point(int(file.read())) file.close else: print "no stored iap. will prompt." apid = sel_access_point(0) StoreAccessPointSelection(apid) if apid: apo = socket.access_point(apid) socket.set_default_access_point(apo) return apo else: return None
def getip(x): x = str(x) all = socket.access_points() for i in range(len(all)): iapid = all[i]["iapid"] pname = all[i]["name"] socket.set_default_access_point(socket.access_point(iapid)) try: ip = socket.gethostbyname(x) except: continue if ip.find("*") > -1: continue else: break #print ip return ip
def sel_access_point(self): """ Select and set the default access point. Return the access point object if the selection was done or None if not """ aps = socket.access_points() if not aps: note(u"No access points available", "error") return None ap_labels = map(lambda x: x['name'], aps) item = popup_menu(ap_labels, u"Access points:") if item is None: return None logging.debug('AP set: %s' % item) apo = socket.access_point(aps[item]['iapid']) socket.set_default_access_point(apo) return apo
def sel_access_point(self): """ Select and set the default access point. Return the access point object if the selection was done or None if not """ aps = socket.access_points() if not aps: note(u"No access points available","error") return None ap_labels = map(lambda x: x['name'], aps) item = popup_menu(ap_labels,u"Access points:") if item is None: return None logging.debug('AP set: %s' % item) apo = socket.access_point(aps[item]['iapid']) socket.set_default_access_point(apo) return apo
def select_access_point(self): """ Select the default access point. Return True if the selection was done or False if not found on <http://croozeus.com/blogs/?p=836> """ aps = socket.access_points() if not aps: appuifw.note(u"No access points available","error") return False ap_labels = map(lambda x: x['name'], aps) item = appuifw.popup_menu(ap_labels,u"Access points:") if item is None: return False self.apo = socket.access_point(aps[item]['iapid']) socket.set_default_access_point(self.apo) return True
def send(self, data='', url=''): #发送网络数据公用函数 import httplib from socket import access_points, access_point, select_access_point, set_default_access_point self.apid = self.aps[eval(self.setting[6])] self.ap = access_point(self.apid['iapid']) set_default_access_point(self.ap) heads = { "Accept": "text/plain", "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "LeXun-PY_G-XWM-ZXF" } try: conn = httplib.HTTPConnection('10.0.0.172:80') conn.request('POST', url, data, heads) res = conn.getresponse() except: pass return res.status, res.reason, res.read()
def localIP(): appuifw.app.menu = [] try: id_list = [ap["iapid"] for ap in socket.access_points()] name_list = [ap["name"] for ap in socket.access_points()] apnid = socket.select_access_point() apn = socket.access_point(apnid) apn.start() ip = apn.ip() body.color = (0, 255, 0) slow_print("Your Local IP :\n") body.color = (0, 0, 255) slow_print(ip) slow_print(" \n") except: body.color = (255, 255, 0) slow_print("No Access Point Selected\n") appuifw.app.menu = [(ru("Check Internet IP"), internetIP), (ru("Check Local IP"), localIP), (ru("About"), about), (ru("Exit"), quit)]
def WakeOnLan(): global config # Construct a six-byte hardware address addr_byte = config['mac'].split(':') hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16), int(addr_byte[1], 16), int(addr_byte[2], 16), int(addr_byte[3], 16), int(addr_byte[4], 16), int(addr_byte[5], 16)) # Build the Wake-On-LAN "Magic Packet"... msg = '\xff' * 6 + hw_addr * 16 # ...and send it to the broadcast address using UDP apo = socket.access_point(config['accesspoint']) socket.set_default_access_point(apo) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.sendto(msg, (config['ip'], 9)) s.close()
def sendToSOS(body, sensorMac, depth, endDate): apFile = open('e:\\SSN\\apid.txt', 'rb') setting = apFile.read() apid = eval(setting) apFile.close() #error checking here for the credit etc. "can you hear me?, yes? wicked!" trace("got credit") apo = socket.access_point(apid) socket.set_default_access_point(apo) sockIP = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # send the request. sockIP = httplib.HTTPConnection('150.229.66.73', 80) sockIP.request('POST', '/HutchinsSOS/sos', body) trace("still here") # check the response. resp = sockIP.getresponse() responsedoc = resp.read() dbm.execute(u'DELETE FROM sensordata WHERE sensorAddr=\'%s\' AND depth = %s AND timeStamp <= %s'%(sensorMac, depth, endDate)) trace("Transmission to SOS complete") trace("returning to 'for' loop, or exiting now")
def download(): #---------------------- copy from here --------------------------------------- try: f = open('e:\\apid.txt', 'rb') setting = f.read() apid = eval(setting) f.close() if not apid == None: apo = socket.access_point(apid) socket.set_default_access_point(apo) else: set_accesspoint() except: set_accesspoint() #------------------------- copy till here -------------------------------------- # and put it before the line of code in your script that invokes a connection to the internet # like here with urllib.urlretrieve(url, tempfile) # your own code here url = "http://www.leninsgodson.com/courses/pys60/resources/vid001.3gp" tempfile = 'e:\\Videos\\video.3gp' urllib.urlretrieve(url, tempfile) appuifw.note(u"Video downloaded", "info")
import inbox, appuifw, e32, messaging, httplib, socket, urllib, time # Setup for T-Mobile apo = socket.access_point(2) socket.set_default_access_point(apo) # Domain info domain = "dev.habwatch.com" handler = "/sms" keyword = "*****@*****.**" print "SMS Gateway Started" print "Domain is:", domain print "Handler is:", handler def createdtstring(secs, format): return time.strftime(format,(time.localtime(secs))) while 1: box = inbox.Inbox() msgs = box.sms_messages() for i in msgs: address = str(box.address(i)) epoch = int(box.time(i)) content = str(box.content(i)) if(content.find(keyword) != -1): info = content.split(" / ") number = info[1] msg = info[2]
appuifw.note(u"Welcome! You will need to set your preferences.", "error") canvas = appuifw.Canvas() appuifw.app.body = canvas w, h = canvas.size img = graphics.Image.new((w, h)) img.clear((255,255,255)) img.text((10,40), u"NoseRub Client v0.1", fill = (0,0,0)) img.text((10,70), u"www.noserub.com", fill = (0,0,0)) canvas.blit(img) location = [] loc_key = [] config = {} read_config() # if user has set a default AP, configure it. ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo) appuifw.app.exit_key_handler = quit appuifw.app.title = u"NoseRub Client" appuifw.app.menu = [(u"Update Location", update), (u"Download locations list",update_list), (u"Preferences", ((u"Base URL", url), (u"User name",user),(u"API Key",api)))] print "NoseRub Client Started" app_lock = e32.Ao_lock() app_lock.wait()
#try: # ip = apo.ip() # print u"Connected to WiFi as %s" % ip #except: # print u"Failed to connect to WiFi" menuitems = [] aps = socket.access_points() for k in aps: menuitems.append(k['name']) menuitems.append(u'LOCAL') id = globalui.global_popup_menu(menuitems, u'Select AP') if id < len(aps): print id, aps[id] apo = socket.access_point(aps[id]['iapid']) socket.set_default_access_point(apo) apo.start() try: ip = apo.ip() except: globalui.global_note(u"Could not Connect!, EXIT") sys.exit() else: # bind to localhost ip = "127.0.0.1" globalui.global_note(u"Your IP:"+ unicode(str(ip))) sys.path.append('e:\\python\\libs')
def wget(url, ap_id=None): '''Downloads a web resource with the HTTP protocol and returns the result ap_id is the access point to use. If it is None, the user will be prompted''' if not url.startswith('http://'): return None #Remove protocol part url = url[7:] #split GET and domain t = url.split('/', 1) #TODO handle IPv6 addresses m = t[0].split(':', 1) if len(m) == 1: host = m[0] port = 80 else: host = m[0] try: port = int(m[1]) except: port = 80 if len(t) > 1: get = '/' + t[1] else: get = '/' hname = host if port != 80: hname += ":%d" % port #Download the file if ap_id == None: ap_id = socket.select_access_point() ap = socket.access_point(ap_id) #socket.set_default_access_point(ap) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) sock.send( "GET %s HTTP/1.1\r\nConnection: close\r\nHost: %s\r\nUser-Agent: RSS-agk\r\n\r\n" % (get, hname)) data = '' while True: r = sock.read(4000) if len(r) == 0: break data += r sock.close() #Release access point ap.stop() return data.split('\r\n\r\n', 1)[1]
def wget(url,ap_id=None): '''Downloads a web resource with the HTTP protocol and returns the result ap_id is the access point to use. If it is None, the user will be prompted''' if not url.startswith('http://'): return None #Remove protocol part url=url[7:] #split GET and domain t=url.split('/',1) #TODO handle IPv6 addresses m=t[0].split(':',1) if len(m)==1: host=m[0] port=80 else: host=m[0] try: port=int(m[1]) except: port=80 if len(t)>1: get='/' + t[1] else: get='/' hname=host if port!=80: hname+=":%d" % port #Download the file if ap_id==None: ap_id=socket.select_access_point() ap=socket.access_point(ap_id) #socket.set_default_access_point(ap) sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect((host,port)) sock.send("GET %s HTTP/1.1\r\nConnection: close\r\nHost: %s\r\nUser-Agent: RSS-agk\r\n\r\n" % (get,hname)) data='' while True: r=sock.read(4000) if len(r)==0: break data+=r sock.close() #Release access point ap.stop() return data.split('\r\n\r\n',1)[1]
import socket ap_id = socket.select_access_point() apo = socket.access_point(ap_id) apo.start() print "PHONE IP IS", apo.ip()
def defaultAP(): ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo)
def shua(): if os.path.exists(DB_FILE): f = file(DB_FILE, "r") lst = [] for line in f: lst.append(line.strip()) f.close() apid = lst[0] cq = lst[1] cm = lst[2] else: list = [] apid = sel_access_point() list.append(apid) yq = appuifw.query('qq号码:'.decode('utf-8'), 'number', 223081080) ym = appuifw.query('qq密码:'.decode('utf-8'), 'code') if yq and ym: list.append(yq) list.append(ym) cq, cm = yq, ym f = file(DB_FILE, "w") for item in list: print >> f, item f.close() def cancel_cb(): pass point = socket.access_point(int(apid)) socket.set_default_access_point(point) dlg = Wait(cn('正在连接网络'), False, cancel_cb) dlg.show() set_body(cn('正在连接网络')) get('http://z.qq.com') dlg.set_label(cn('请等待…\n正在获取网页地址')) a = step1('http://z.qq.com') set_body('打开网页'.decode('utf-8') + a) #过滤登录我的QQ空间 strgl = '\xe7\x99\xbb\xe5\xbd\x95\xe6\x88\x91\xe7\x9a\x84QQ\xe7\xa9\xba\xe9\x97\xb4' dlg.set_label(cn('如果您长期停留在某一界面请尝试更换接入点或退出程序稍后再试…')) c = lookurl(a, strgl) set_body('打开网页'.decode('utf-8') + c) dlg.set_label(cn('请等待\n正在登录空间…')) d = get_sid(c, cq, cm) set_body('提取sid为:'.decode('utf-8') + d) #手机美文链接 gl = '\xe6\x89\x8b\xe6\x9c\xba\xe7\xbe\x8e\xe6\x96\x87' libao = '\xe6\x81\xad\xe5\x96\x9c\xe6\x82\xa8\xe8\x8e\xb7\xe5\xbe\x97\xe5\xb9\xb8\xe8\xbf\x90\xe5\xa4\xa7\xe7\xa4\xbc\xe5\x8c\x85' dlg.set_label(cn('正在预读美文日志链接…')) set_body(cn('正在预读美文链接…')) m = lookurl(a, gl) dlg.close() url = m[:m.find('&sid=') + 5] + d for i in range(500): readnext(url) #读日志 set_body(cn('正在预读美文链接…')) url = lookurl(url, '\xe4\xb8\x8b\xe9\xa1\xb5') set_body(cn('正在检测进度…')) libaourl = lookurl(myzone_url, libao) if libaourl != None: set_body(cn('恭喜你,刷到了\n快点击<我的空间>看看吧…')) break if url == None: break if libaourl == None: set_body(cn('呜呜呜,还没刷到喔…\n继续…加油…')) point.stop()
def findip(self): appuifw.app.menu = [(ru("Stop"), self.stop), (ru("Exit"), self.exit)] self.timert.cancel() self.compress() try: self.apn = socket.access_point(self.id) self.apn.start() appuifw.app.title = ru("Finding IP...") self.ip = str(self.apn.ip()) self.text.color = 0, 200, 200 if self.i > 200: self.i = 1 self.stop() self.app() return self.console.write("%s.IP: " % self.i) self.text.color = 0, 0, 255 self.console.write("%s " % self.ip) self.i += 1 self.ipfound = self.ip.find(self.sets.IPHUNT) if self.sets.IPHUNT and self.ipfound == 0: self.text.color = 255, 0, 0 self.console.write("<Found>") if self.sets.VIBRATE and miso_import: try: miso.vibrate(50, 100) except: self.sets.VIBRATE = 0 self.sets.save() pass self.timert.cancel() self.timertitle("IP Found") self.compress() self.text.color = 0 self.console.write("\n") self.savelog() self.timerip.cancel() if self.sets.RUNSS: e32.ao_sleep(0.5) #appuifw.note(u"Launching Simple Server") e32.ao_sleep(0.5) try: e32.start_exe(ss, '') except: try: e32.start_exe("E:\\Sys\\bin\\" + ss, '') except: try: e32.start_exe("F:\\Sys\\bin\\" + ss, '') except: appuifw.note( u"Simple Server is not Installed or Unknown Error", "error") self.sets.RUNSS = 0 self.sets.save() else: self.console.write("\n") self.apn.stop() self.savelog() self.compress() self.timerip.after(1, self.findip) except: self.write("No Network or Unknown Error") appuifw.app.menu = [(ru("Start"), self.start), (ru("Settings"), self.settings), (ru("About"), self.about), (ru("Exit"), self.exit)] pass
def access_point(): ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo)
def onSetAccessPoint(self): self.accessPointId = socket.select_access_point() self.accessPoint = socket.access_point(self.accessPointId) socket.set_default_access_point(self.accessPoint) self.saveSettings()