Audiovox P965 Datový list Strana 80

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 280
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 79
Manual:API Python3
77
Manual:API Python3
Summary
Since python language have introduced changes to syntax when going from 2.x to 3.x some adjustments had to be
made for old code from API.
Code for Python3
code
#!/usr/bin/python3
import sys, posix, time, binascii, socket, select
import hashlib
class ApiRos:
"Routeros api"
def __init__(self, sk):
self.sk = sk
self.currenttag = 0
def login(self, username, pwd):
for repl, attrs in self.talk(["/login"]):
chal = binascii.unhexlify((attrs['=ret']).encode('UTF-8'))
md = hashlib.md5()
md.update(b'\x00')
md.update(pwd.encode('UTF-8'))
md.update(chal)
self.talk(["/login", "=name=" + username,
"=response=00" + binascii.hexlify(md.digest()).decode('UTF-8') ])
def talk(self, words):
if self.writeSentence(words) == 0: return
r = []
while 1:
i = self.readSentence();
if len(i) == 0: continue
reply = i[0]
attrs = {}
for w in i[1:]:
j = w.find('=', 1)
if (j == -1):
attrs[w] = ''
else:
attrs[w[:j]] = w[j+1:]
r.append((reply, attrs))
if reply == '!done': return r
Zobrazit stránku 79
1 2 ... 75 76 77 78 79 80 81 82 83 84 85 ... 279 280

Komentáře k této Příručce

Žádné komentáře