2
Votes

reverse dns lookup to populate names in OMADA SDN

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.
 
2
Votes

reverse dns lookup to populate names in OMADA SDN

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.
reverse dns lookup to populate names in OMADA SDN
reverse dns lookup to populate names in OMADA SDN
2024-06-13 19:41:59 - last edited 2024-06-13 20:01:48
Hardware Version:
Firmware Version:

just a small note for people who would like to get the omada SDN to populate names automatically based on their local DNS... here is my small script which seems to do the trick while waiting for TPlink to implement this really really basic function in their code... 

it has been tested on ubuntu, running opnsense FW as DHCP server, with unboundID DNS and tplink EAP&switches.

 

note: you might want to audit the script and the python libary before using it in PRODUCTION....

 

 

#!/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

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









 

 

 
#1
Options
2 Reply
Re:reverse dns lookup to populate names in OMADA SDN
2024-06-14 01:44:21

 Hi @ffsb 

 

Thank you for your sharing! 

 

>> Omada EAP Firmware Trial Available Here << *Try filtering posts on each forum by Label of [Early Access]*
#2
Options
Re:reverse dns lookup to populate names in OMADA SDN
2024-06-14 17:27:44 - last edited 2024-06-14 17:31:50

version 2 is a bit faster and cleaner because it uses omada's list of clients instead of scanning the whole subnet:

 

 

#!/usr/bin/bash

version=0
changelog="version=$version, 13-Jun-2024, initial build"

version=2
changelog="version=$version, 14-Jun-2024, swapped loop from by-subnet to by-omada-clients-mac, saving before and after files in /var/tmp"


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...  everytime the script runs it will keep a copy of the omada clients output
before and after the script execution in /var/tmp/omadaclients.*.dns2omada

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"
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


cat $omadaclients | while read mac ip name device port junk
do
    clientname=""
    clientmac=$mac
    #
    # debugging
    # echo "parsing mac=$mac ip=$ip name=$name device=$device port=$port junk=$junk"

    if [[ $ip = "" ]] || [[ $ip = "-" ]]
    then
        echo "skiping $mac because omada does not have an IP for it"
    else    
        clientname=$(nslookup $ip $dns_server 2>/dev/null | fgrep "=" |cut -f2 -d"=" |cut -f1 -d"."|tail -1)
        if [[ $clientname = ""  ]]
        then
            echo "skipping $ip because I cant resolve it"
        else
            echo "setting hostname for $ip to $clientname for mac $clientmac "        
            $omadabin set-client-name $clientmac $clientname            
        fi
    fi
    unset  mac ip name device port junk    
done
cat $omadaclients > /var/tmp/omadaclients.before.dns2omada
$omadabin clients  > /var/tmp/omadaclients.after.dns2omada








 
#3
Options