Command line tools for controlling Netgear LB1120 / LB2120 4G modems
These tools were tested on a Netgear LB1120 and LB2120, however they probably work on other models.
Firmware Version: M18Q2_v12.09.163431
App Version: NTG9X07C_12.09.05.30
Web App Version: LBHDATA_03.03.103.176
Requires bash and curl. Tested with curl 7.68.0 and bash 5.0.17.
Reboot Modem
This script will allow you to automate reboots of your device. I've noticed my LB1120 tends to stop passing traffic after a few days so I have a scheduled 1AM daily reboot task.
1#!/bin/bash
2# Reboot supported Netgear 4G modems from CLI.
3HOSTNAME=192.168.5.1
4PASSWORD=YourSuperSecurePassword
5
6LOGIN_FORM=`curl -s -L -D - http://$HOSTNAME`
7LOGIN_COOKIE=`echo "$LOGIN_FORM" | grep Set-Cookie | grep -v unknown | cut -d= -f 2-`
8TOKEN=`echo "$LOGIN_FORM" | grep token | cut -d\" -f 6`
9AUTH_COOKIE=`curl -s -D - --cookie "sessionId=$LOGIN_COOKIE" \
10--data-urlencode "token=$TOKEN" \
11--data-urlencode "ok_redirect=/index.html" \
12--data-urlencode "err_redirect=/index.html" \
13--data-urlencode "session.password=$PASSWORD" \
14http://$HOSTNAME/Forms/config | grep Set-Cookie | grep -v unknown | cut -d= -f 2-`
15
16RESULT=`curl -s -L --cookie "sessionId=$AUTH_COOKIE" \
17--data-urlencode "general.shutdown=restart" \
18--data-urlencode "err_redirect=/error.json" \
19--data-urlencode "ok_redirect=/success.json" \
20--data-urlencode "token=$TOKEN" \
21http://$HOSTNAME/Forms/config`
22
23echo "$RESULT"
Send SMS / text message
This script is useful for sending alerts even when your Internet connection(s) are down.
1#!/bin/bash
2# Send SMS messages from the CLI on supported Netgear 4G modems.
3# https://github.com/JeffWDH/Netgear-4G-SMS-Script
4HOSTNAME=192.168.5.1
5PASSWORD=YourSuperSecurePassword
6PHONENUMBER=$1
7MESSAGE=${@:2}
8
9USAGE="netgearsms <phonenumber> <message>
10Maximum length of message is 335 characters."
11
12if [[ $PHONENUMBER == "" ]];
13then
14 echo "$USAGE"
15 echo
16 echo "No phone number supplied. Exiting."
17 exit
18fi
19
20if [[ $MESSAGE == "" ]];
21then
22 echo "$USAGE"
23 echo
24 echo "No message supplied. Exiting."
25 exit
26fi
27
28MESSAGE_LENGTH=${#MESSAGE}
29
30# Message maximum length = 70
31# 5 * 70 = 350 characters
32# -15 for part counter = 335 max
33
34if [ $MESSAGE_LENGTH -gt 335 ]
35then
36 echo "Message is too long (maximum 335 characters)"
37 exit
38fi
39
40LOGIN_FORM=`curl -s -L -D - http://$HOSTNAME`
41LOGIN_COOKIE=`echo "$LOGIN_FORM" | grep Set-Cookie | grep -v unknown | cut -d= -f 2-`
42TOKEN=`echo "$LOGIN_FORM" | grep token | cut -d\" -f 6`
43AUTH_COOKIE=`curl -s -D - --cookie "sessionId=$LOGIN_COOKIE" \
44--data-urlencode "token=$TOKEN" \
45--data-urlencode "ok_redirect=/index.html" \
46--data-urlencode "err_redirect=/index.html" \
47--data-urlencode "session.password=$PASSWORD" \
48http://$HOSTNAME/Forms/config | grep Set-Cookie | grep -v unknown | cut -d= -f 2-`
49
50sendSMS () {
51 RESULT=`curl -s -L --cookie "sessionId=$AUTH_COOKIE" \
52 --data-urlencode "sms.sendMsg.receiver=$PHONENUMBER" \
53 --data-urlencode "sms.sendMsg.text=$1" \
54 --data-urlencode "sms.sendMsg.clientId=client" \
55 --data-urlencode "action=send" \
56 --data-urlencode "err_redirect=/error.json" \
57 --data-urlencode "ok_redirect=/success.json" \
58 --data-urlencode "token=$TOKEN" \
59 http://$HOSTNAME/Forms/smsSendMsg`
60
61 if [[ "$RESULT" != '{ "success": true }' ]]; then
62 echo "Message send failed."
63 exit
64 fi
65}
66
67if [ $MESSAGE_LENGTH -gt 70 ]
68then
69 NUM_PARTS=$((($MESSAGE_LENGTH+67-1)/67))
70 for ((X=0; X<$NUM_PARTS; X++))
71 do
72 START=$(($X*67))
73 SUBSTR="[$((X+1))]${MESSAGE:$START:67}"
74 sendSMS "$SUBSTR"
75 done
76else
77 sendSMS "$MESSAGE"
78fi
79
80# If it got here then it should have been a success.
81echo "Message sent."