Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion populate omada client names from reverse dns #46

Open
FlyingToto opened this issue Jun 13, 2024 · 0 comments
Open

suggestion populate omada client names from reverse dns #46

FlyingToto opened this issue Jun 13, 2024 · 0 comments

Comments

@FlyingToto
Copy link

  • first of all thank you for this library it is a huge time saver!
  • I wrote a very basic shell script to leverage your "omada clients" output and "omada set-client-name" to populate hostnames automatically based on reverse dns. H
  • Here is the code if you want to add it to your library or maybe provide it as an add-in for people interested (I also posted to tplink in case they want to add something similar in SDN directly):
#!/usr/bin/bash
HELP="
dns2omada.sh is the most simplistic script ever meant to paliate one of dumbest laziest lack of feature of the tp-link OMADA SDN software....
it simply populate the OMADA client's name based on DNS name... 
using a python omada api...
Assumptions: 
- you already have a local DNS server able to perform reverse DNS resolution per IP.
- you already have omada SDN setup on the network
- you should create an OMADA admin account dedicated to this process using a very long random password string without any special character 
- my subnet is simply from 192.168.0.1 to 192.168.0.256 so I have a simple loop, you might have to modify the script if your subnet is class B 
with an outer loop etc...
usage: 
    1) install python: sudo apt install python3-pip
    2) install the omada python api: pip install tplink-omada-client
    3) update the parameters CHANGE_ME values in the scipt below
    4) run the script manually or in cron... 
"

# these should be self-explanatory
omada_username="CHANGEME_mrpotatoe"
omada_password="CHANGEME_lfdaruiRWGFD335qw324z"
omada_site="CHANGEME_homesweethome"
omada_url="https://CHANGEME_omada.mylocaldomain" 
subnet=CHANGEME_192.168.0
dns_server=CHANGEME_192.168.0.1
omadabin=/CHANGEME/bin/omada   # the absolute path to the omada binarie whch gets installed with the client.




if [[ $# -gt 0 ]]
then
    echo $HELP
    exit 3
fi

if fgrep -v grep $0 | fgrep CHANGEME  >/dev/null
then
    echo "ERROR: you forgot to change these varialbes from $0:"
    fgrep -v grep $0 | fgrep CHANGEME 
    echo "$HELP"
    exit 4
fi
$omadabin -t myomada target --url $omada_url --user $omada_username --password $omada_password --site $omada_site --set-default

omadaclients=/tmp/omadaclients.$$.txt

$omadabin clients  > $omadaclients
clientname=""
let ip4thfield=1
while [[ $ip4thfield -lt 256 ]]
do 
    clientname=""
    clientmac=""
    clientname=$(nslookup ${subnet}.$ip4thfield $dns_server 2>/dev/null | fgrep "=" |cut -f2 -d"=" |cut -f1 -d"."|tail -1)
    if [[ $clientname != "" ]]
    then        
        clientmac=$(fgrep " ${subnet}.$ip4thfield " $omadaclients| cut -f1 -d" "|tail -1)
        if [[ $clientmac != "" ]]
        then
            echo "setting hostname for ${subnet}.$ip4thfield to $clientname for mac $clientmac "        
            $omadabin set-client-name $clientmac $clientname            
        else
            echo "skipping ${subnet}.$ip4thfield  because omada does not see any client MAC for it"
        fi
    else
        echo "skipping ${subnet}.$ip4thfield  because I cant resolve it"
    fi
    let ip4thfield=ip4thfield+1 
done
rm -f $omadaclients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant