-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjumpcloud-radius-updateip.rsc
31 lines (25 loc) · 1.19 KB
/
jumpcloud-radius-updateip.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
:local myhostname [/system identity get name]
:local mydate ([/system clock get date])
:local mytime ([/system clock get time])
:local toEmail [email protected]
:global lastip
# using Mikrotik embedded service /ip/cloud/
# https://help.mikrotik.com/docs/display/ROS/Cloud
:global getmyip [/ip/cloud/print as-value without-paging]
:global myip ($getmyip->"public-address")
# external website like ifconfig.io or ifconfig.io
#:global getmyip [/tool fetch url="https://ifconfig.io/ip" as-value output=user];
# (simply remove /n character)
#:global myip [ :pick ($getmyip->"data") 0 ( [ :len ($getmyip->"data") ] -1 ) ];
:if ([:typeof $lastip] ~ "(nil|nothing)") do= {
:log info nolastip
:global lastip ($getmyip->"data")
}
:if (($myip != $lastip)) do={
:log info ("MYIP: $myip")
:tool e-mail send to=$toEmail subject="$myhostname NEW IP" body="$myip"
:set lastip $myip
/tool fetch http-method=put mode=https http-header-field="x-api-key:XXX,content-type:application/json" http-data="{\"name\":\"$myhostname $mydate ($mytime)\",\"networkSourceIp\":\"$myip\",\"sharedSecret\":\"XXX\"}" output=none url="https://console.jumpcloud.com/api/radiusservers/XXX"
} else={
#:log info ("MYIP $hostname: No update needed")
}