Giter Site home page Giter Site logo

tlwpa4220's Introduction

TL-WPA4220 go package

GitHub Super-Linter

Go library for the TL-WPA4220

Usage

As a library

package main

import (
    "fmt"

    "github.com/angelbarrera92/tlwpa4220/pkg/tlwpa4220"
)

func main() {
    t := tlwpa4220.Client{
        Username: "admin",
        Password: "hopeItsNotAdmin",
        IP:       "192.168.2.1",
    }

    wireless, err := t.WirelessStatistics()
    if err != nil {
        panic(err)
    }

    for _, device := range wireless.Data {
        fmt.Println(device.Mac)
    }

    err = t.Reboot()
    if err != nil {
        fmt.Println(err)
        panic(err)
    }
}

As a CLI

This package also provides a CLI to interact with the TL-WPA4220. It provides the following commands:

  • tlwpa4220 cli: Interact with the TL-WPA4220 using a CLI
  • tlwpa4220 serve-metrics: Expose metrics from the TL-WPA4220 in Prometheus format

Build

go build -o tlwpa4220 cmd/main.go
# or
make build

Run commands

The subcommands are:

  • wireless-statistics: Get the wireless statistics
  • powerline-statistics: Get the powerline statistics
  • reboot: Reboot the device
$ ./tlwpa4220 cli --device-ip="192.168.2.1" --password="hopeItsNotAdmin" wireless-statistics
2022/10/21 17:48:42 Running command wireless-statistics
2022/10/21 17:48:42 Wireless statistics: {"success":true,"timeout":false,"data":[{"mac":"XX-YY-ZZ-46-1E-40","type":"2.4GHz","encryption":"wpa2-psk","rxpkts":"0","txpkts":"0","ip":"192.168.22.22","devName":"NSA"}],"others":{"max_rules":64}}
$ ./tlwpa4220 cli --device-ip="192.168.2.1" --password="hopeItsNotAdmin" reboot
$ ./tlwpa4220 cli --device-ip="192.168.2.1" --password="hopeItsNotAdmin" powerline-statistics
2022/10/21 21:23:57 Running command powerline-statistics
2022/10/21 21:23:57 Powerline statistics: {"timeout":false,"success":true,"data":[{"device_mac":"ZZ-YY-XX-2D-6C-40","device_password":"","rx_rate":"282","tx_rate":"186","status":"on"}]}

Run the metrics exporter

This package also provides a metrics exporter to expose the wireless statistics as Prometheus metrics.

$ ./tlwpa4220 serve-metrics --device-ip="192.168.2.1" --password="hopeItsNotAdmin"
2022/10/21 17:51:28 Starting the metric recording thread
2022/10/21 17:51:28 Serving metrics on 0.0.0.0:8080/metrics
Metrics

The metrics are:

  • connected_devices_total: Number of connected devices
  • connected_devices: Number of connected devices per device type
  • connected_devices_txpkts: Number of transmitted packets per device
  • connected_devices_rxpkts: Number of received packets per device
  • powerline_devices_total: Number of powerline devices
  • powerline_device: Powerline device information and status
  • powerline_device_txpkts: Number of transmitted packets per powerline device
  • powerline_device_rxpkts: Number of received packets per powerline device
$ curl http://localhost:8080/metrics
# HELP connected_devices Connected devices
# TYPE connected_devices gauge
connected_devices{devname="NSA",ip="192.168.22.22",mac="XX:YY:ZZ:46:1E:40"} 1
# HELP connected_devices_rxpkts The total number of received packets
# TYPE connected_devices_rxpkts gauge
connected_devices_rxpkts{devname="NSA",ip="192.168.22.22",mac="XX:YY:ZZ:46:1E:40"} 0
# HELP connected_devices_total The total number of connected devices
# TYPE connected_devices_total gauge
connected_devices_total 1
# HELP connected_devices_txpkts The total number of transmitted packets
# TYPE connected_devices_txpkts gauge
connected_devices_txpkts{devname="NSA",ip="192.168.22.22",mac="XX:YY:ZZ:46:1E:40"} 0
# HELP powerline_device The powerline device
# TYPE powerline_device gauge
powerline_device{mac="ZZ:YY:XX:2D:6C:40"} 1
# HELP powerline_device_rxpkts The powerline device rxpkts
# TYPE powerline_device_rxpkts gauge
powerline_device_rxpkts{mac="ZZ:YY:XX:2D:6C:40"} 283
# HELP powerline_device_txpkts The powerline device txpkts
# TYPE powerline_device_txpkts gauge
powerline_device_txpkts{mac="ZZ:YY:XX:2D:6C:40"} 178
# HELP powerline_devices_total The total number of powerline devices
# TYPE powerline_devices_total gauge
powerline_devices_total 1

Development

Use the Makefile to build and lint the code.

Requirements:

make clean lint build

License

GPLv3

tlwpa4220's People

Contributors

angelbarrera92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tlwpa4220's Issues

ACTION REQUIRED: Changes to pulling Chainguard Images

Hey there Chainguard here.

We noticed that you are using Chainguard Images, thank you! We wanted to make you aware of an upcoming change that will impact your project.

Starting August 16, 2023 public users will no longer be able to pull images from our registry (cgr.dev/chainguard) by tags other than latest or latest-dev. Please see the announcement for more information.

You are currently using the following.

In https://github.com/angelbarrera92/tlwpa4220/blob/0c47604ccbe8ec1791fa1a1b3da30d896cb945a1/Makefile:

  • cgr.dev/chainguard/go:1.19

Our goal is to prevent your project from experiencing any disruptions. Please see the migration guide for options.

If there's more we can do to help please reply to this issue or email us at [email protected].

Thank you!

Malformed HTTP status code

Hello.
Thanks for your work.

I tried to use your code with my TL-WPA4220 (HW rev TL-WPA4220 5.0, FW : 1.0.12 Build 230309 Rel.64136n (6985)) without success.

Here's the command line test result :

sysadmin@morpheus:~/tpa4220/tlwpa4220-main$ ./tlwpa4220 cli --device-ip="192.168.0.197" --password="xxxxx" wireless-statistics
2023/07/26 11:33:23 Running command wireless-statistics
2023/07/26 11:33:23 Error getting wireless statistics: Post "http://192.168.0.197/admin/wireless?form=statistics": net/http: HTTP/1.x transport connection broken: malformed HTTP status code "192.168.0.197\x00\x00User-Agent\x00"
2023/07/26 11:33:23 Post "http://192.168.0.197/admin/wireless?form=statistics": net/http: HTTP/1.x transport connection broken: malformed HTTP status code "192.168.0.197\x00\x00User-Agent\x00"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.