fstercq / freepybox

Manage your freebox in Python using the Freebox OS API
23 stars 31 forks source link

Add a connection module to get WAN status #8

Closed lboue closed 5 years ago

lboue commented 5 years ago

Hello,

I would push this pull request to add a connection module to get WAN status. It works for me and my FreeboxV6 with V6 API.

from freepybox import Freepybox

# Instantiate Freepybox class using default application descriptor 
# and default token_file location
fbx = Freepybox()

# Connect to the freebox with default http protocol
# and default port 80
# Be ready to authorize the application on the Freebox if you use this
# example for the first time
fbx.open('mafreebox.freebox.fr', 80)

# Extract WAN interface status (GET /api/v6/connection/full) using connection API
fbx_connection_status_details = fbx.connection.get_status_details()
print(fbx_connection_status_details)

print('WAN ipv4 address: {0}'.format(fbx_connection_status_details['ipv4']))
print('WAN ipv6 address: {0}'.format(fbx_connection_status_details['ipv6']))
print('WAN status: {0}'.format(fbx_connection_status_details['state']))

print('WAN down bandwidth: {0}'.format(fbx_connection_status_details['bandwidth_down']))
print('WAN up bandwidth: {0}'.format(fbx_connection_status_details['bandwidth_up']))
print('WAN type: {0}'.format(fbx_connection_status_details['type']))
print('WAN media: {0}'.format(fbx_connection_status_details['media']))

# Close the freebox session
fbx.close()
$ python3 ./freepybox/freeboxV6-wan.py 
{   'bandwidth_down': 14820000,
    'bandwidth_up': 1020000,
    'bytes_down': 276225021,
    'bytes_up': 48628438,
    'ipv4': '78.197.C.D',
    'ipv4_port_range': [0, 65535],
    'ipv6': '2a01:e34:abcd:abcd::1',
    'media': 'xdsl',
    'rate_down': 4870,
    'rate_up': 2810,
    'state': 'up',
    'type': 'rfc2684'}
{   'bandwidth_down': 14820000,
    'bandwidth_up': 1020000,
    'bytes_down': 276225021,
    'bytes_up': 48628438,
    'ftth': {   'has_sfp': True,
                'link': False,
                'sfp_alim_ok': True,
                'sfp_has_power_report': False,
                'sfp_has_signal': False,
                'sfp_present': False},
    'ipv4': '78.197.C.D',
    'ipv4_port_range': [0, 65535],
    'ipv6': '2a01:e34:abcd:abcd::1',
    'media': 'xdsl',
    'rate_down': 4870,
    'rate_up': 2810,
    'state': 'up',
    'type': 'rfc2684',
    'xdsl': {   'modulation': 'adsl',
                'protocol': 'adsl2plus_a',
                'status': 'showtime',
                'uptime': 6602}}

WAN ipv4 address: 78.197.C.D
WAN ipv6 address: 2a01:e34:abcd:abcd::1
WAN status: up
WAN down bandwidth: 14820000
WAN up bandwidth: 1020000
WAN type: rfc2684
WAN media: xdsl

Regards