ΠΠΎΠ³Π΄Π° Ρ ΠΏΡΠΈΡΠ΅Π» ΡΠ°Π±ΠΎΡΠ°ΡΡ Π² ΡΡΡ ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΡ, Ρ ΠΌΠ΅Π½Ρ ΡΠΆΠ΅ ΠΈΠΌΠ΅Π»Π°ΡΡ Π½Π΅ΠΊΠΎΡΠΎΡΠ°Ρ Π±Π°Π·Π° ΠΏΠΎ ip Π°ΠΏΠΏΠ°ΡΠ°ΡΠ°ΠΌ, Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΈΠΌ ΡΠ΅ΡΠ²Π΅ΡΠ°ΠΌ Ρ asterisk ΠΈ Π½Π°ΡΠ»Π΅ΠΏΠΊΠΎΠΉ Π² Π²ΠΈΠ΄Π΅ FreeBPX. ΠΡΠΎΠΌΠ΅ ΡΠΎΠ³ΠΎ ΠΏΠ°ΡΠ°Π»Π»Π΅Π»ΡΠ½ΠΎ ΡΠ°Π±ΠΎΡΠ°Π»Π° Π°Π½Π°Π»ΠΎΠ³ΠΎΠ²Π°Ρ ΠΠ’Π‘ Samsung IDCS500 ΠΈ Π² ΠΎΠ±ΡΠ΅ΠΌ-ΡΠΎ Π±ΡΠ»Π° ΠΎΡΠ½ΠΎΠ²Π½ΠΎΠΉ ΡΠΈΡΡΠ΅ΠΌΠΎΠΉ ΡΠ²ΡΠ·ΠΈ Π² ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΈ, ip ΡΠ΅Π»Π΅ΡΠΎΠ½ΠΈΡ ΡΠ°Π±ΠΎΡΠ°Π»Π° ΡΠΎΠ»ΡΠΊΠΎ Π΄Π»Ρ ΠΎΡΠ΄Π΅Π»Π° ΠΏΡΠΎΠ΄Π°ΠΆ. Π Π²ΡΠ΅ Π±Ρ Π²Π°ΡΠΈΠ»ΠΎΡΡ ΡΠ°ΠΊ ΠΈ Π΄Π°Π»ΡΡΠ΅, Π½ΠΎ Π² ΠΎΠ΄ΠΈΠ½ ΠΏΡΠ΅ΠΊΡΠ°ΡΠ½ΡΠΉ Π΄Π΅Π½Ρ Π±ΡΠ» Π΄Π°Π½ ΡΠΊΠ°Π· ΠΏΠ΅ΡΠ΅Π²ΠΎΠ΄ΠΈΡΡ Π²ΡΠ΅Ρ
Π½Π° IP ΡΠ΅Π»Π΅ΡΠΎΠ½ΠΈΡ, Π±ΡΠ»ΠΈ ΠΎΠ³ΠΎΠ²ΠΎΡΠ΅Π½Ρ ΡΡΠΎΠΊΠΈ, Π·Π°ΠΊΡΠΏΠ»Π΅Π½ΠΎ ΠΎΠ±ΠΎΡΡΠ΄ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΈ ΠΏΠ»Π°Π½ ΠΏΠΎ ΠΏΠ΅ΡΠ΅Π²ΠΎΠ΄Ρ ΠΏΡΠ΅Π΄ΠΏΡΠΈΡΡΠΈΡ Π² 21 Π²Π΅ΠΊ ΡΡΠ°Π» ΠΏΡΠ΅ΡΠ²ΠΎΡΡΡΡΡ Π² ΠΆΠΈΠ·Π½Ρ.
ΠΠ΅ΡΠ²ΠΎΠ΅ ΡΡΠΎ Π½Π°ΡΠΈΠ½Π°Π΅Ρ Π±Π΅ΡΠΏΠΎΠΊΠΎΠΈΡΡ Π² ΡΠ°ΠΊΠΎΠΉ ΡΠΈΡΡΠ°ΡΠΈΠΈ, ΡΡΠΎ Π±ΡΡΡΡΠΎ Π½Π°ΡΠ°ΡΡΠ°ΡΡΠ΅Π΅ ΠΊΠΎΠ»-Π²ΠΎ ΡΠ΅Π»Π΅ΡΠΎΠ½Π½ΡΡ
Π°ΠΏΠΏΠ°ΡΠ°ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠΌΠΈ Π½Π°Π΄ΠΎ ΠΊΠ°ΠΊ-ΡΠΎ ΡΠΏΡΠ°Π²Π»ΡΡΡ, Π²ΡΠΎΡΠΎΠ΅, ΡΡΠΎ ΡΠΈΠ»ΡΠ½ΠΎ ΡΡΠ΅Π²ΠΎΠΆΠΈΠ»ΠΎ Π±ΡΠ»Π° ΡΠ΅Π»Π΅ΡΠΎΠ½Π½Π°Ρ ΠΊΠ½ΠΈΠ³Π°. ΠΡΠ»ΠΈ Ρ ΠΏΠ΅ΡΠ²ΡΠΌ Π½Π°ΠΌ ΠΌΠΎΠ³ ΠΏΠΎΠΌΠΎΡΡ Endpoint Manager (ΠΊΠΎΡΠΎΡΡΠΉ ΠΊΡΡΠ°ΡΠΈ Π²ΡΠΏΠΈΠ»ΠΈΠ»ΠΈ ΠΈΠ· ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΡ
Π²Π΅ΡΡΠΈΠΉ FreePBX), ΡΠΎ Π²ΠΎΡ Ρ ΠΊΠ½ΠΈΠ³ΠΎΠΉ Π²ΠΎΠ·Π½ΠΈΠΊΠ°Π»ΠΈ Π½Π΅ΠΊΠΎΡΠΎΡΡΠ΅ Π²ΠΎΠΏΡΠΎΡΡ:
- ΠΠΎ ΠΏΠ΅ΡΠ²ΡΡ ΠΊΠ°ΠΊ ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠΏΠ΅ΡΠΈΡΡ Π΅Ρ ΡΠΎΡΠ½ΠΎΡΡΡ ΠΏΡΠΈ ΠΏΠΎΡΡΠΎΡΠ½Π½ΠΎΠΉ ΡΠΌΠ΅Π½Π΅ Π΄ΠΈΡΠ»ΠΎΠΊΠ°ΡΠΈΠΈ/ΡΠ΅ΠΊΡΡΠ΅ΡΡΠΈ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Π΅ΠΉ?
- ΠΠΎ Π²ΡΠΎΡΡΡ , ΠΊΠ°ΠΊ ΠΏΠΎΠ»Π½ΠΎΡΡΡΡ ΠΎΠ±Π΅Π·Π»ΠΈΡΠΈΡΡ ΡΠ΅Π»Π΅ΡΠΎΠ½Ρ. Π Π½Π΅ Π·Π°ΠΏΠΎΠ»Π½ΡΡΡ ΠΊΠ°ΠΆΠ΄ΡΠΉ ΡΠ°Π· ΠΈΠΌΡ ΠΊΠΎΠ½ΡΠ°ΠΊΡΠ°?
ΠΠ°Π΄Π°ΡΠΊΠ° Π±ΡΠ»Π° ΠΈΠ½ΡΠ΅ΡΠ΅ΡΠ½Π°Ρ, ΡΠ΅ΡΠ΅Π½ΠΈΠ΅ Π½Π΅ Π·Π°ΡΡΠ°Π²ΠΈΠ»ΠΎ ΡΠ΅Π±Ρ Π΄ΠΎΠ»Π³ΠΎ ΠΆΠ΄Π°ΡΡ. Π‘Π΅ΠΉΡΠ°Ρ Ρ ΠΏΡΠΈΠ²Π΅Π΄Ρ ΠΏΠΎΠ»Π½ΡΠΉ Π»ΠΈΡΡΠΈΠ½Π³, Π° ΠΏΠΎΡΠΎΠΌ ΡΠ°Π·Π±Π΅ΡΠ΅ΠΌ ΠΏΠΎ ΠΏΠΎΡΡΠ΄ΠΊΡ.
from scapy.all import sniff
from scapy.layers.inet import IP
import mysql.connector
import ldap
import getpass
import tftpy
import requests
import os
import time
from string import replace
def conn_ldap(login):
ad = ldap.initialize('ldap://***.local')
ad.simple_bind_s('voip@***.local', 'password')
basedn = 'OU=IT,DC=***,DC=LOCAL'
basedn_user = 'OU=***,OU=***,DC=***,DC=LOCAL'
scope = ldap.SCOPE_SUBTREE
filterexp = "(&(sAMAccountName=" + login + ")(ObjectClass=person))"
filterexp2 = "(&(ObjectClass=organizationUnit))"
attrlist = ['cn']
attrlist2 = ['OU']
search = ad.search_s(basedn, scope, filterexp, attrlist)
adname = search[0][1]['cn'][0].decode('utf-8')
if adname == ' ':
search = ad.search_s(basedn_user, scope, filterexp2, attrlist2)
for i in range(1, len(search)+1):
group = search[i][1]['ou'][0]
basedn_user2 = 'OU='+group+','+basedn_user
search = ad.search_s(basedn_user2, scope, filterexp, attrlist)
adname = search[0][1]['cn'][0].decode('utf-8')
if adname != ' ':
return adname
adname = search[0][1]['cn'][0].decode('utf-8')
ad.unbind_s()
return adname
def tftp_file_change(config,place,adname,current_account,current_account_password):
client = tftpy.TftpClient("192.168.0.3", 69)
client.download('template.cfg', place)
fileread = open(place, 'r')
line = fileread.readlines()
fileread.close()
line[5] = (('account.1.label = ').encode('utf-8') + adname.encode('utf-8') + 'n')
line[2] = (('account.1.auth_name = ').encode('utf-8') + current_account.encode('utf-8') + 'n')
line[3] = (('account.1.display_name = ').encode('utf-8') + current_account.encode('utf-8') + 'n')
line[6] = (('account.1.password = ').encode('utf-8') + current_account_password[0][0] + 'n')
filewrite = open(place, 'w')
for i in line:
filewrite.write(i)
filewrite.close()
print place
print config
client.upload(config,place)
def get_phone_inform(ipaddr):
fileconf = requests.get('http://admin:admin@'+ipaddr+'/servlet?phonecfg=get[&accounts=1]')
conf = fileconf.text.split('|')
current_account = conf[2]
return current_account
def sniff_frame():
pcapf = sniff(count=1, timeout=70, filter="dst host 192.168.0.3 and port 5060")
if len(pcapf) == 0:
exit()
frame = pcapf[0]
macaddr = frame.src
print macaddr[:8]
if macaddr[:8] != '80:5e:c0':
exit()
ipaddr = frame[0][IP].src
return macaddr, ipaddr
def conn_mysql(query,fquery,macaddr,qwery2):
connect = mysql.connector.connect(host='192.168.0.3', database='voip', user='voip_wr', password='***')
cursor = connect.cursor()
cursor.execute(fquery)
state = cursor.fetchall()
state = bool(state[0][0])
if state == True:
cursor.execute(qwery2)
connect.commit()
connect.close()
else:
cursor.execute(query)
connect.commit()
connect.close()
def check_account(current_account):
connect = mysql.connector.connect(host='192.168.0.3', database='asterisk', user='voip_wr', password='***')
cursor = connect.cursor()
qwery = 'select data from sip where id=' + current_account + ' and keyword="secret";'
cursor.execute(qwery)
password = cursor.fetchall()
if password == ' ':
exit()
else:
return password
if __name__ == '__main__':
macaddr, ipaddr = sniff_frame()
current_account = get_phone_inform(ipaddr)
current_account_password = check_account(current_account)
macaddr = macaddr.replace(':', '')
ipaddr = ipaddr.decode('utf-8')
adname = conn_ldap(getpass.getuser())
query = 'INSERT INTO station (mac, ip, name, number) VALUES (' + '"' + macaddr + '",' + '"' + ipaddr + '",' + '"' + adname + '",' + '"' + get_phone_inform(ipaddr) + '"' + ')'
qwery2 = 'UPDATE station SET ip=' + '"' + ipaddr + '"' + ', name=' + '"' + adname + '"' + ', number=' + '"' + get_phone_inform(ipaddr) + '"' + ' WHERE mac=' + '"' + macaddr + '"'
fquery = 'SELECT EXISTS(SELECT mac FROM voip.station WHERE mac=' + '"' + macaddr + '")'
query = query.encode('utf-8')
fquery = fquery.encode('utf-8')
config = macaddr + '.cfg'
place = os.path.expanduser("~") + "" + "AppDataLocal" + config
conn_mysql(query,fquery,macaddr,qwery2)
tftp_file_change(config,place,adname,current_account,current_account_password)
requests.get('http://admin:admin@'+ipaddr+'/cgi-bin/ConfigManApp.com?key=AutoP')
requests.get('http://admin:admin@'+ipaddr+'/cgi-bin/ConfigManApp.com?key=Reboot')
ΠΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° Π·Π°ΠΏΡΡΠΊΠ°Π΅ΡΡΡ Π½Π° ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ΅ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ ΠΈ ΡΠ°Π±ΠΎΡΠ°Π΅Ρ ΠΏΡΠΈ ΡΡΠ»ΠΎΠ²ΠΈΠΈ, ΡΡΠΎ ΠΊΠΎΠΌΠΏΡΡΡΠ΅Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ ΠΊ ΡΠ΅ΡΠΈ ΡΠ΅ΡΠ΅Π· ΡΠ΅Π»Π΅ΡΠΎΠ½, ΡΠ°ΠΊ ΠΊΠ°ΠΊ Yealink T19 Π½Π΅ ΡΠΌΠ΅Π΅Ρ ΡΠ°Π±ΠΎΡΠ°ΡΡ Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠ»ΡΠ·Π°.
ΠΠ»Ρ Π½Π°ΡΠ°Π»Π° Π½Π°ΠΌ Π½Π΅ΠΎΠ±Ρ ΠΎΠ΄ΠΈΠΌΠΎ ΠΏΠΎΠ½ΡΡΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ Π»ΠΈ? ΠΈ ΠΊΠ°ΠΊΠΎΠΉ mac ΠΈ ip ΠΈΠΌΠ΅Π΅Ρ Π½Π°Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½.
def sniff_frame():
pcapf = sniff(count=1, timeout=70, filter="dst host 192.168.0.3 and port 5060")
if len(pcapf) == 0:
exit()
frame = pcapf[0]
macaddr = frame.src
print macaddr[:8]
if macaddr[:8] != '80:5e:c0':
exit()
ipaddr = frame[0][IP].src
return macaddr, ipaddr
Π‘Π΄Π΅ΡΡ ΠΌΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ ΡΡΠ½ΠΊΡΠΈΡ sniff ΠΈΠ· ΡΡΠ°Π΅ΠΌΠ²ΠΎΡΠΊΠ° scapy, Ρ ΠΏΠΎΠΌΠΎΡΡΡ Π½Π΅Ρ ΠΌΡ ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ Π·Π°ΡΠ°Π½Π΅Π΅ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΡΠΉ udp ΠΏΠ°ΠΊΠ΅Ρ, ΠΆΠ΄Π΅ΠΌ 70 ΡΠ΅ΠΊΡΠ΄ ΠΈ Π΅ΡΠ»ΠΈ Π½ΠΈΡΠ΅Π³ΠΎ Π½Π΅ ΠΏΠΎΠΉΠΌΠ°Π»ΠΈ Π²ΡΡ ΠΎΠ΄ΠΈΠΌ.
count=1, timeout=70, filter="dst host 192.168.0.3 and port 5060"
ΠΠ°Π»Π΅Π΅ ΡΠ±Π΅ΠΆΠ΄Π°Π΅ΠΌΡΡ, ΡΡΠΎ Π°ΠΏΠΏΠ°ΡΠ°Ρ Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»ΡΠ½ΠΎ Yealink ΠΈ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌ Π½Π΅ΠΎΠ±Ρ ΠΎΠ΄ΠΈΠΌΡΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ (ip ΠΈ mac).
Π‘ ΠΏΠΎΠΌΠΎΡΡΡ ΡΠΏΠ΅ΡΠΈΠ°Π»ΡΠ½ΠΎΠ³ΠΎ Π·Π°ΠΏΡΠΎΡΠ° Π²ΡΡΡΠ½ΡΠ΅ΠΌ ΡΠ΅ΠΊΡΡΠΈΠΉ Π°ΠΊΠΊΠ°ΡΠ½Ρ Π½Π° ΡΠ΅Π»Π΅ΡΠΎΠ½Π΅. ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ ΡΠΊΠ°ΡΠΈΠ²Π°Π΅ΡΡΡ ΡΠ΅ΠΊΡΡΠ°Ρ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΡ Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Π° ΠΈ ΡΠ°ΡΠΏΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ.
def get_phone_inform(ipaddr):
fileconf = requests.get('http://admin:admin@'+ipaddr+'/servlet?phonecfg=get[&accounts=1]')
conf = fileconf.text.split('|')
current_account = conf[2]
return current_account
ΠΡΡΡΠ½ΡΠ΅ΠΌ ΠΏΠ°ΡΠΎΠ»Ρ Π΄Π»Ρ Π΄Π°Π½Π½ΠΎΠ³ΠΎ Π°ΠΊΠΊΠ°ΡΠ½ΡΠ°. ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ ΠΎΠ±ΡΠ°ΡΠ°Π΅ΠΌΡΡ ΠΊ ΡΠ°Π±Π»ΠΈΡΠ΅ asterisk.sip ΠΈ Π² Π½Π΅ΠΉ ΠΊ ΠΏΠΎΠ»Ρ data.
def check_account(current_account):
connect = mysql.connector.connect(host='192.168.0.3', database='asterisk', user='voip_wr', password='***')
cursor = connect.cursor()
qwery = 'select data from sip where id=' + current_account + ' and keyword="secret";'
cursor.execute(qwery)
password = cursor.fetchall()
if password == ' ':
exit()
else:
return password
ΠΡ ΠΈ Π΄Π»Ρ ΡΠΈΠ½Π°Π»ΡΠ½ΠΎΠ³ΠΎ ΡΡΠ°ΠΏΠ° ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌΡΡ ΠΊ ldap AD ΠΈ Ρ ΠΏΠΎΠΌΠΎΡΡΡ sAMAccountName ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌΠΎΠ³ΠΎ ΡΠ΅ΡΠ΅Π· ΡΡΠ½ΠΊΡΠΈΡ getpass.getuser() Π·Π°Π±ΠΈΡΠ°Π΅ΠΌ cn ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ (Π² ΠΊΠΎΡΠΎΡΠΎΠΌ ΠΎΠ±ΡΡΠ½ΠΎ ΡΠΎΠ΄Π΅ΡΠΆΠΈΡΡΡ Π€ΠΠ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ).
def conn_ldap(login):
ad = ldap.initialize('ldap://***.local')
ad.simple_bind_s('voip@***.local', 'password')
basedn = 'OU=***,DC=***,DC=LOCAL'
basedn_user = 'OU=***,OU=***,DC=***,DC=LOCAL'
scope = ldap.SCOPE_SUBTREE
filterexp = "(&(sAMAccountName=" + login + ")(ObjectClass=person))"
filterexp2 = "(&(ObjectClass=organizationUnit))"
attrlist = ['cn']
attrlist2 = ['OU']
search = ad.search_s(basedn, scope, filterexp, attrlist)
adname = search[0][1]['cn'][0].decode('utf-8')
if adname == ' ':
search = ad.search_s(basedn_user, scope, filterexp2, attrlist2)
for i in range(1, len(search)+1):
group = search[i][1]['ou'][0]
basedn_user2 = 'OU='+group+','+basedn_user
search = ad.search_s(basedn_user2, scope, filterexp, attrlist)
adname = search[0][1]['cn'][0].decode('utf-8')
if adname != ' ':
return adname
adname = search[0][1]['cn'][0].decode('utf-8')
ad.unbind_s()
return adname
ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌΡΡ ΠΊ Π·Π°ΡΠ°Π½Π΅Π΅ ΡΠΎΠ·Π΄Π°Π½Π½ΠΎΠΉ ΡΠ°Π±Π»ΠΈΡΠ΅ Π² Π±Π΄ (Ρ ΠΌΠ΅Π½Ρ Π±ΡΠ»Π° ΡΠΎΠ·Π΄Π°Π½Π° ΡΠ°ΠΌ ΠΆΠ΅) ΠΈ Π²Π½ΠΎΡΠΈΠΌ Π²ΡΠ΅ ΡΠΎ, ΡΡΠΎ ΠΌΡ ΡΠ·Π½Π°Π»ΠΈ, Π° ΠΈΠΌΠ΅Π½Π½ΠΎ: ip, mac, ΠΈΠΌΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ.
def conn_mysql(query,fquery,macaddr,qwery2):
connect = mysql.connector.connect(host='192.168.0.3', database='voip', user='voip_wr', password='***')
cursor = connect.cursor()
cursor.execute(fquery)
state = cursor.fetchall()
state = bool(state[0][0])
if state == True:
cursor.execute(qwery2)
connect.commit()
connect.close()
else:
cursor.execute(query)
connect.commit()
connect.close()
ΠΠ° ΡΡΠΎΠΌ ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΠ»ΠΎ Π±Ρ ΠΎΡΡΠ°Π½ΠΎΠ²ΠΈΡΡΡ, Π²Π΅Π΄Ρ ΠΌΡ ΡΠΆΠ΅ ΡΠΎΠ·Π΄Π°Π»ΠΈ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΡΡ Π°Π΄ΡΠ΅ΡΠ½ΡΡ ΠΊΠ½ΠΈΠ³Ρ ΡΠΏΡΠΎΡΠΈΡΠ΅ Π²Ρ, Π½ΠΎ Ρ ΠΏΠΎΡΠ΅Π» Π΄Π°Π»ΡΡΠ΅ ΠΈ ΠΏΡΠΈΠΊΡΡΡΠΈΠ» ΡΡΠ΄Π° ΠΆΠ΅ Π°Π²ΡΠΎΠΏΡΠΎΠ²ΠΈΠ·ΠΈΠΎΠ½Π½ΠΈΠ½Π³ Π°ΠΏΠΏΠ°ΡΠ°ΡΠΎΠ².
ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ Ρ Π·Π°ΡΠ°Π½Π΅Π΅ Π½Π°ΡΡΡΠΎΠ΅Π½Π½ΠΎΠ³ΠΎ tftp ΡΠ΅ΡΠ²Π΅ΡΠ° ΡΠΊΠ°ΡΠΈΠ²Π°Π΅ΡΡΡ template ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΡ, Π² ΠΊΠΎΡΠΎΡΡΡ ΠΌΡ Π²Π½ΠΎΡΠΈΠΌ ΡΠ²ΠΎΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΠΈ ΡΠΎΡ ΡΠ°Π½ΡΠ΅ΠΌ Ρ ΠΊΠ°ΠΊ mac.cfg. Π’ΠΎΠ΅ΡΡΡ Π΄Π»Ρ Yealink ΡΡΡΠ΅ΡΡΠ²ΡΡΡ Π΄Π²Π° Π²ΠΈΠ΄Π° ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ, ΠΎΠ΄Π½Π° Π³Π»ΠΎΠ±Π°Π»ΡΠ½Π°Ρ, Π° Π²ΡΠΎΡΠ°Ρ ΠΏΡΠΈΠΌΠ΅Π½ΡΠ΅ΡΡΡ ΠΊ ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΠΎΠΌΡ ΡΠ΅Π»Π΅ΡΠΎΠ½Ρ ΠΈ Π΄ΠΎΠ»ΠΆΠ½Π° Π±ΡΡΡ Π²ΠΈΠ΄Π° mac_ΡΠ΅Π»Π΅ΡΠΎΠ½Π°.cfg
ΠΠΎΡΠ»Π΅ Π²ΡΠ΅Ρ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ Π² ΡΠ°ΠΉΠ»Π΅ ΠΈ ΡΠΎΡ ΡΠ°Π½Π΅Π½ΠΈΡ Π΅Π³ΠΎ ΠΎΠ±ΡΠ°ΡΠ½ΠΎ Π½Π° tftp ΡΠ΅ΡΠ²Π΅Ρ ΠΌΡ ΠΎΡΠ΄Π°Π΅ΠΌ ΠΊΠΎΠΌΠ°Π½Π΄Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Ρ Π½Π° ΠΏΡΠΎΠ²ΠΈΠ·ΠΈΠΎΠ½ΠΈΠ½Π³ ΠΈ ΠΏΠ΅ΡΠ΅Π·Π°Π³ΡΡΠ·ΠΊΡ Π°ΠΏΠΏΠ°ΡΠ°ΡΠ°.
def tftp_file_change(config,place,adname,current_account,current_account_password):
client = tftpy.TftpClient("192.168.0.3", 69)
client.download('template.cfg', place)
fileread = open(place, 'r')
line = fileread.readlines()
fileread.close()
line[5] = (('account.1.label = ').encode('utf-8') + adname.encode('utf-8') + 'n')
line[2] = (('account.1.auth_name = ').encode('utf-8') + current_account.encode('utf-8') + 'n')
line[3] = (('account.1.display_name = ').encode('utf-8') + current_account.encode('utf-8') + 'n')
line[6] = (('account.1.password = ').encode('utf-8') + current_account_password[0][0] + 'n')
filewrite = open(place, 'w')
for i in line:
filewrite.write(i)
filewrite.close()
print place
print config
client.upload(config,place)
requests.get('http://admin:admin@'+ipaddr+'/cgi-bin/ConfigManApp.com?key=AutoP')
requests.get('http://admin:admin@'+ipaddr+'/cgi-bin/ConfigManApp.com?key=Reboot')
ΠΠΎΡΠ»Π΅ ΠΏΠ΅ΡΠ΅Π·Π°Π³ΡΡΠ·ΠΊΠΈ Π°ΠΏΠΏΠ°ΡΠ°ΡΠ° ΠΌΡ ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΏΠΎΠ»Π½ΠΎΠ΅ ΡΠΈΠΎ Π½Π° ΡΠΊΡΠ°Π½Π΅ ΡΠ΅Π»Π΅ΡΠΎΠ½Π° + Π²ΡΠ΅Π³Π΄Π° ΠΊΠΎΡΡΠ΅ΠΊΡΠ½ΠΎ Π·Π°ΠΏΠΎΠ»Π½Π΅Π½Π½ΡΡ Π°Π΄ΡΠ΅ΡΠ½ΡΡ ΠΊΠ½ΠΈΠ³Ρ Π² Π»ΠΈΡΠ΅ ΠΠ, Π΄Π°Π»Π΅Π΅ ΠΎΡΡΠ°Π΅ΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΡΠΈΠΊΡΡΡΠΈΡΡ XML ΠΈ Π½Π΅ΠΌΠ½ΠΎΠ³ΠΎ PHP Π΄Π»Ρ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΎΠ³ΠΎ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ ΠΊΠΎΠ½ΡΠ΅Π½ΡΠ°. Π’Π°ΠΊΠΈΡ ΠΏΡΠΈΠΌΠ΅ΡΠΎΠ² ΠΌΠ°ΡΡΠ°, Π΅ΡΡΡ Π΄Π°ΠΆΠ΅ Ρ ΡΠ°ΠΌΠΎΠ³ΠΎ YEALINK.
P.S.: ΠΠ»Ρ ΠΏΡΡΠ΅ΠΉ ΠΌΠ°ΡΡΡΠ°Π±ΠΈΡΡΠ΅ΠΌΠΎΡΡΠΈ ΠΌΠΎΠΆΠ½ΠΎ Π²ΡΠ½Π΅ΡΡΠΈ ΠΎΡΠ½ΠΎΠ²Π½ΡΠ΅ Π½Π°ΡΡΡΠΎΠΉΠΊΠΈ (ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΠ΅) Π² ΠΎΡΠ΄Π΅Π»ΡΠ½ΡΠΉ ΡΠ°ΠΉΠ»ΠΈΠΊ.
ΠΡΡΠΎΡΠ½ΠΈΠΊ: habr.com