原理 : dubbo_telnet连接zk再请求接口。
一、dubbo接口扫描:
#coding=utf8
import sys
from kazoo.client import KazooClient
Host = '' # Doubble服务器IP
Port = # Doubble服务端口
urls = []
zk = KazooClient(hosts="{}:2181".format(Host))
zk.start()
list = zk.get_children("dubbo")
for i in list:
# print i
#if 'pacific' in i:
if true:
# print i
gg = zk.get_children("/dubbo/{}/consumers".format(i))
if gg:
for j in gg:
url = urllib.unquote(j)
if url.startswith('dubbo:'):
urls.append(url.split('?')[0].split('dubbo://')[1])
gg = zk.get_children("/dubbo/{}/providers".format(i))
if gg:
for j in gg:
url = urllib.unquote(j)
if url.startswith('dubbo:'):
urls.append(url.split('?')[0].split('dubbo://')[1])
services = {}
for i in urls:
path, service = i.split('/')
if not services.get(path):
services.update({path: []})
services[path].append(service)
print json.dumps(services, indent=4)
二、zk连接
import dubbo_telnet
import telnetlib
Host = '' # Doubble服务器IP
Port = # Doubble服务端口
conn = dubbo_telnet.connect(Host, Port)
command = 'invoke %s.%s("%s")'%('interface','method','param')
conn.set_connect_timeout(10)
conn.set_encoding('utf8')
conn.invoke('interface', 'method', 'param')
conn.do(command)