Freebox瘦客户端

pyfbx的Python项目详细描述


Freebox客户端库

功能

  • 全面的API覆盖范围
  • https和mdns发现
  • 瘦客户端包装库(<;200行)
  • 执行大多数任务的小脚本

pipeline statuscoverage report

库使用

库可用于创建自己的脚本。 rest api在运行时生成,为所有freebox子系统创建类属性。

>>>frompyfbximportFbx>>>f=Fbx()# By default, this will perform MDNS discovery>>>f=Fbx(nomdns=True)# Use faster http api discovery>>>f.<TAB>f.Airmediaf.Download_Configf.Lanf.Rrdf.Upnpavf.Callf.Download_Feedsf.Lcdf.Sharef.Vpnf.Connectionf.Freeplugf.Natf.Storagef.Vpn_Clientf.Contactsf.Fsf.Network_Sharef.Switchf.Wifif.Dhcpf.Ftpf.Parentalf.Systemf.mksession(f.Downloadf.Igdf.Pvrf.Uploadf.register(>>>f.Freeplug.<TAB>f.Freeplug.Get_a_particular_Freeplug_information(f.Freeplug.Reset_a_Freeplug(f.Freeplug.Get_the_current_Freeplugs_networks(# Register application to get app token. Physical access is required.>>>token=f.register("AppId","My App","PC")# Generate session token>>>f.mksession(app_id="AppId",token=token)>>>help(f.Lan.Update_the_current_Lan_configuration)HelponmethodUpdate_the_current_Lan_configuration:Update_the_current_Lan_configuration(post_data)methodofpyfbx.client.LaninstanceUpdatethecurrentLanconfigurationUrlparameters:Postdata:PostData>>>help(f.Contacts.Access_a_given_contact_entry)HelponmethodAccess_a_given_contact_entry:Access_a_given_contact_entry(id)methodofpyfbx.client.ContactsinstanceAccessagivencontactentryUrlparameters:idPostdata:>>>f.Lan.Get_the_current_Lan_configuration(){'name_dns':'freebox-server','name':'Freebox Server','name_mdns':'Freebox-Server','mode':'router','name_netbios':'Freebox_Server','ip':'192.168.1.254'}# Any subsequent call to mksession will refresh the session token>>>f.mksession()

脚本

包含的脚本可以执行许多任务。

基础知识

$ pyfbx -h
usage: pyfbx [-h][-a APP_ID][-t TOKEN][-v][-n][-j][-d DELAY][-u URL][-s SEND][-c COMMAND]

optional arguments:
  -h, --help            show this help message and exit
  -a APP_ID, --app_id APP_ID
                        application identifier
  -t TOKEN, --token TOKEN
                        token (or f:<filename>)
  -v, --verbose         increase verbosity to INFO, use twice for DEBUG
  -n, --http            disable MDNS and use http known address
  -j, --json            json output
  -d DELAY, --delay DELAY
                        cylically send command(number of seconds)
  -u URL, --url URL     specific url to query
  -s SEND, --send SEND  url to send json to
  -c COMMAND, --command COMMAND
                        command, defaults to
                        System.Get_the_current_system_info()

首先,注册应用程序:

$ pyfbx -a SuperAppId

在设备上完成注册后,记下应用程序令牌。 您还可以创建一个文件,其中token作为第一行,application id作为第二行。

使用此应用令牌,获取会话令牌以执行测试命令。

$ pyfbx -t '<TOKEN>' -a SuperAppId

$ cat token.txt
2OUDy4hhM/KLQ7ru+70gfi83h5A4DUoOpDztOfqM4c2wuUiWJ+gXTHB1SbxHAFP7
SuperAppId

$ pyfbx -t f:token.txt -c 'Connection.Get_the_current_Connection_status()'{'bandwidth_down': 1000000000,
    [..]'state': 'up',
    'type': 'ethernet'}

note:不要忘记用引号转义标记和命令。

高级

您可以在Freebox上运行任何命令并检索完整的结果或单个值

$ pyfbx -t f:/home/foo/token.txt SuperAppId -c 'Contacts.Create_a_contact(\post_data={"display_name": "Sandy Kilo", "first_name": "Sandy", "last_name":"Kilo"})'{'birthday': '',
    [..]'photo_url': ''}

$ pyfbx -u https://0s2efr3i.fbxos.fr:15628 -c "Connection.Get_the_current_Connection_status()['rate_up']" -t f:token.txt
1700

使用“延迟”选项,可以循环发送命令:

$ pyfbx -d 1 -c "Connection.Get_the_current_Connection_status()['rate_up']" -t f:token.txt
424605071053400

使用send选项,结果可以发送到远程url。 在下面,结果以json格式循环发送到example.com。

pyfbx -j -s http://example.com/values -d 10 -c "Connection.Get_the_current_Connection_status()" -t f:token.txt

可以执行几个命令。 这里,两个命令循环发送,结果发送到一个url。

pyfbx -c 'System.Get_the_current_system_info()' -c 'Connection.Get_the_current_Connection_status()' -d 10 -j -s http://localhost:8182/telegraf -t f:token.txt

带有json格式的telegraf http listener v2输入插件可用于实时绘制数据。

Telegraf和Graphana绘图

您可以在/etc/telegraf/telegraf.d/freebox中使用电报配置:

[[inputs.http_listener_v2]]
    service_address = ":8182"
    path = "/telegraf"
    methods = ["POST"]
    read_timeout = "10s"
    write_timeout = "10s"
    max_body_size = "5KB"
    data_format = "json"
    name_override = "pyfbx"

Grafana

开发

测试

您可以使用

pip3 install -r requirements-dev.txt
pytest tests

对库机制进行了测试。要获得100%的覆盖率,需要在其默认IP(192.168.1.254)上设置一个空闲框。

API描述是生成的,因此没有经过功能测试。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
spring JSTL:绝对uri:http://java.sun.com/jsp/jstl/core无法在两个站点中解析。xml或与此应用程序一起部署的jar文件   java在Junit测试中找不到失败的符号   java为什么在没有同步块的情况下调用wait()、notify()或notifyAll()不是编译器错误?   使用onDraw()绘制多个位图的java Android在曲面视图上放大缩小画布   在java中比较args值和字符串   java更改文件中的特定字节   java TransformerFactory破坏<html>标记中的<input>和<br>标记   azure appinsights java自定义指标不起作用   Java泛型在实现接口的类上指定上界,接口本身指定上界   java AS400 prog和动态类路径   java应用程序截图时收到空消息   java无法从片段中获取上下文   找不到java配置单元UDF类   linux是一个提供java的接口。lang.NoClassDefFoundError   java如何使用面向对象建模创建此数据库