API scripts - IP address post because VPN masks the address - Pulse Secure - also gets jssID with API

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
12-11-2017
02:31 PM
- last edited on
03-04-2025
07:11 AM
by
kh-richa_mig
Hopefully this will help someone.
At my current company they use Pulse Secure for VPN. The setup masks the IP locally so when you do a recon/inventory it doesn't actually pull the IP.
For support they have a website that the local user can go to and get the IP.
I wrote a script that curls the site and then uses the API to PUT the IP to the computer record based on serial number lookup so when a tech speaks to a user on VPN they can update the IP.
I have it PUT to both the IP and the Reported IP so the tech won't have to wait for the timeout on control of the computer on the Reported IP.
Obviously the parsing is specific to the site I'm pulling from and I'm basically a hack when it comes to scripting but you'll get the idea.
Not sure if there is an easier way but this is also a quick way to get the jssid with the API (bonus!)
!/bin/bash
jssUser="username"
jssPass="password"
jssUrl="https://companydomain.jamfcloud.com"
ipUrl="https://getmyip.companydomain.com"
Get Serial Number for local computer
serial_number=$(ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}' | sed '$s/"//'g)
Get JSS ID using the serial number and API
jssid=$(/usr/bin/curl -sku $jssUser:$jssPass -H "Accept: application/xml" $jssUrl/JSSResource/computers/serialnumber/${serial_number}/subset/general -X GET | xpath //computer/general/id[1] 2>/dev/null | sed -e 's/<id>//' | sed -e 's/</id>//')
Get the local IP address from the CBS myip site
ipaddress=$(curl -s $ipUrl | grep "Your IP is" | sed '$ s/Your IP is //' | sed '$ s/.$//')
echo "$serial_number"
echo "$jssid"
echo "$ipaddress"
Put the local IP address that was just discovered
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "${jssUser}":"${jssPass}" -d "<computer><general><ip_address>$ipaddress</ip_address></general></computer>" "${jssUrl}"/JSSResource/computers/id/"${jssid}";
sleep 1;
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "${jssUser}":"${jssPass}" -d "<computer><general><last_reported_ip>$ipaddress</last_reported_ip></general></computer>" "${jssUrl}"/JSSResource/computers/id/"${jssid}";
