We have it up in the menu bar on all our machines.
http://www.monkeybreadsoftware.de/Software/IPinmenubar.shtml
@activitymonitor unfortunately that would involve distributing it to all our mac clients, then instructing the end users on what to look for, and then instructing the help desk to ask for the user to get it from that menu item. It's not really practical for our purposes, and would most likely cause more confusion than ever. Our help desk doesn't really have a good grasp on English or on Macs, so I'm trying to keep it as simple as possible so that the help desk doesn't need to learn anything new, and the user has an easy option using a mechanism they're already familiar with, namely Self Service.
@znilsson, this is one I use from Rusty at PSU.
#!/bin/bash
################################################################################
#Display IP Address and Hostname of Computer
#Written to be used with Playtpus to create a app.
#Written by Rusty Myers
################################################################################
################################################################################
#Functions
################################################################################
function testinterface {
en0test=`ifconfig en0 | grep -q 'inet ' && echo en0`
en1test=`ifconfig en1 | grep -q 'inet ' && echo en1`
# echo $en0test
# echo $en1test
if [ "$en0test" == "en0" ]
then
activeinterface=en0
elif [ "$en1test" == "en1" ]
then
activeinterface=en1
else
activeinterface=None
fi
}
function displayip {
if [ "$activeinterface" == "None" ]
then
ipaddress="None"
else
ipaddress=`ipconfig getifaddr $activeinterface`
fi
}
function displaydialog {
echoserial=`/usr/bin/osascript << EOT
tell app "System Events"
Activate
display dialog "Your IP address is $ipaddress. Your computer name is $computername" buttons "OK" default button 1 with title "IP Address and Computer Name"
end tell
EOT`
echo $echoserial
}
################################################################################
#Variables
################################################################################
computername=`scutil --get ComputerName`
################################################################################
#
################################################################################
testinterface
displayip
displaydialog
I'd probably write a script that checks for ethernet enabled and pulls the IP address and hands it to jamf helper to display in a popup. Put it in self service and then ask the user to press the button.
If you wanted to get fancier you could use network setup to detect if they are on Ethernet, Airport, Thunderbolt Ethernet, etc... and pull the active one.
start with an If statement looking for ... networksetup -getnetworkserviceenabled Ethernet
to return Enabled.
then a ReportIpAddress=networksetup getinfo Ethernet|grep IP| awk '{print $3}'
to get the numher
then send that info to jamf helper.
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportIpAddress -button1 "Ok" -cancelButton 1 -timeout 10;
Jason, thanks for the script. It returns the IP address correctly on devices that only have one NIC active, but on some systems, it returns the information twice. It appears it is drawing a dialog for each active network interface, but only provides the IP address of en0.
Have you seen that behavior? Any way to easily return the values of each active NIC?
Couldn't resist. did this today.
this will give you consecutive popups for any active IP addresses.
I use detecting a subnet to tell me if that interface has an IP.
#! /bin/bash
# Name: MyIP.sh
# Version: 1.0
# Author: Peter Gawlocki
SUBonTB=`networksetup -getinfo Thunderbolt Ethernet|grep Subnet| wc |awk '{print $1}'`
SUBonWiFi=`networksetup -getinfo Wi-Fi|grep Subnet| wc |awk '{print $1}'`
SUBonEnet=`networksetup -getinfo Ethernet|grep Subnet| wc |awk '{print $1}'`
if [ $SUBonEnet = 1 ]
then
ReportEnetAddress=`networksetup getinfo Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportEnetAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonWiFi = 1 ]; then
ReportWiFiAddress=`networksetup getinfo Wi-Fi|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Wireless is: "$ReportWiFiAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonTB = 1 ]; then
ReportTBENAddress=`networksetup getinfo Thunderbolt Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportTBENAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
@PeterG thanks for posting this. I added in the Display Ethernet my designers use.
#! /bin/bash
# Name: MyIP.sh
# Version: 1.0
# Author: Peter Gawlocki
SUBonTB=`networksetup -getinfo Thunderbolt Ethernet|grep Subnet| wc |awk '{print $1}'`
SUBonDTB=`networksetup -getinfo Display Ethernet|grep Subnet| wc |awk '{print $1}'`
SUBonWiFi=`networksetup -getinfo Wi-Fi|grep Subnet| wc |awk '{print $1}'`
SUBonEnet=`networksetup -getinfo Ethernet|grep Subnet| wc |awk '{print $1}'`
if [ $SUBonEnet = 1 ]
then
ReportEnetAddress=`networksetup getinfo Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportEnetAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonWiFi = 1 ]; then
ReportWiFiAddress=`networksetup getinfo Wi-Fi|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Wireless is: "$ReportWiFiAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonTB = 1 ]; then
ReportTBENAddress=`networksetup getinfo Thunderbolt Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportTBENAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonDTB = 1 ]; then
ReportTBENAddress=`networksetup getinfo Display Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Display Ethernet is: "$ReportTBENAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
@Kevin I use that script wrapped as an app on my NetBoot sets. @PeterG may be a better choice for Self Service.
Freaking fantastic. That is exactly what I needed, thanks so much. Confirmed it works using different interfaces and everything.
@jhbush1973][/url as I was describing what I wrote to Sunny, our other CCA, she said, "Why don't you wrap it and put it in their Applications folder?" heh... we are all on the same page.... love JAMF Nation.
I am looking to populate self service with as much helpful stuff I can... because I can't hire staff :-(
I use the subnet detect thing when I wrote another script for controlling which Thunderbolt Ethernet Adapter can be used with which computer.
Since our 'current' network security uses MAC address to allow/deny access I can't give out a TbEn adapter to a user and have them bring in a non-company computer and use the company adapter and get on the network.
The script compares the MAC address of the adapter to a plist that we 'hid' and uses jamf helper to display a message if a mismatch is found. It also shuts down the TbEn Interface to make it unusable. It is a launched that runs every 15 seconds. (checks if the TbEn interface pulls an IP) then Acts, if needed.
Interesting… I put this in Self Service and it works wonderfully.
However… on my Desktop–and so far ONLY on my Desktop, the results are returned as expected, but they are returned three times.
Any ideas?
Are your results exactly the same (wording)? (like Ethernet repeating 3 times?
If so, and you get ethernet three times... if you turn on WiFi also do you get:
Alerts like this order... Ethernet, WiFi, Ethernet, WiFi, Ethernet, WiFi?
or Ethernet, Ethernet, Ethernet, WiFi, WiFi, WiFi, ?
Do you have multiple interfaces actively pulling IPs?
Since there is no loop in the script, it does not seem possible to run multiple times.
Is it added multiple times in the Policy?
Yes, exact wording three times. I have two NICs active and I get the results returned three times for each. If I run the script in Terminal, it only returns results once. Just as a policy does it behave this way…
Every other Mac I run it on in Self Service only returns results once. I have tried it on several Macs now - they all work fine. Same policy, pulling the same script.
Same here. I get a total of 4 pop ups-2 for each connected interface.
Running this via Self Service works hit or miss right now and I'm not really sure why. The policy shows as succeeded, but the JAMF helper boxes don't show up.
Hi Everyone,
Saw this thread today and thought some cool stuff was going on so I marked it for later. I whipped up an example of how you can display all Network IP addresses to an end user. Just in case they happened to be connected to WiFi, their HotSpot, Ethernet, etc.
#!/bin/bash
# dispaly information to end user
# set IFS for new line
# use unset IFS to reset it to default value
IFS=$'
'
# get list of networkservices exlcuding disabled services
NetServices=$(networksetup -listallnetworkservices | grep -v '*')
for service in ${NetServices} ; do
echo "${service} is currently assigned: $(networksetup -getinfo ${service} | awk '/IP address:/ { gsub("[a-z]", ""); print $3 }' | sed 's/://g')" >> /tmp/netinfo.txt
done
# applescript to display dialog
osascript <<AppleScript
tell application "Finder"
activate
display dialog "Your Network Information is:
$(cat /tmp/netinfo.txt)" buttons {"OK"} default button 1
end tell
AppleScript
unset IFS
# clean our temp file
srm /tmp/netinfo.txt
exit 0
What it looks like:
external image link
Unfortunately, I had a really hard time getting all that text to fit in my JAMF Helper examples. Like I said, not sure if this is even of interest to you all, but I figured if you displayed everything to an end user and they started reading off their IPs and services the Help Desk person would know what is best to connect to. Like if they happen to drag their service order to WiFi above Ethernet and the Help Desk person wants to remote in to install software, they would preferably want to do that over Ethernet.
Sorry for the pipes, my awk skills are slipping I had to pipe to sed to get rid of a pesky ":" that kept getting tossed in output. I also just loop through all Network Services that are currently enabled. That way you don't have to write specific code looking for specific network adapters.
EDIT - hooked up my hotspot to show how it will display multiple IPs when connected to multiple services, also should have mentioned I purposely disabled all my FW networking interfaces as a proof of concept so that is why they are excluded:
external image link
Hope this helps out
Thanks
Tom
I thought I'd throw in another variation here. This one uses bash arrays, will report on any hardware ports with active IP addresses and skip the rest for clarity, and uses cocoaDialog for the messaging, although in theory you could easily use AppleScript or jamfHelper with this just as well.
#!/bin/bash
## Name: show-my-ips.sh
## Path to cocoaDialog. Customize to your environment
cdPath="/path/to/cocoaDialog.app/Contents/MacOS/cocoaDialog"
## Get the Mac's name
MACNAME=$(scutil --get ComputerName)
IFS=""
## Place all hardware ports into array
while read port; do
HWPORTS+=( "$port" )
done < <(echo $(networksetup -listallhardwareports | awk -F': ' '/Hardware Port/{ print $NF }'))
## Place all device ids into array
while read device; do
DEVICES+=( "$device" )
done < <(echo $(networksetup -listallhardwareports | awk '/Device/{ print $NF }'))
## Loop over hardwareport array checking for active IP and add any to new array along with device IDs
for ((i = 0; i < ${#HWPORTS[@]}; i++)); do
IP=$(ipconfig getifaddr ${DEVICES[$i]})
if [[ ! -z "$IP" ]]; then
IPADDRESSES+=("${HWPORTS[$i]} (${DEVICES[$i]}): ${IP}
")
fi
done
## Reset IFS to space
IFS=" "
## Clean up final array for message
ACTIVEIPS=$(echo -e "${IPADDRESSES[@]}" | sed 's/^ *//')
MESSAGE="The following are details about your computer:
Mac Name:
${MACNAME}
Device Name (Port): IP Address:
${ACTIVEIPS[@]}"
"$cdPath" msgbox
--title "My IP Addresses"
--text "Details about your Mac"
--informative-text "$MESSAGE"
--button1 " OK "
--icon network
A screen shot of what it looks like. It would normally report the Mac name, but I removed that for the image.
external image link
I think IPMENUBAR works great. sure, there is the task of distributing it and executing it on the endpoint, but its very simple and in the users menu bar all the time. there is not much instruction the user will need other than look on your top right for a number that begins with your x.x.x.(depending on the class network you are using) - all my users (even the technically challenged ones) can see this number very quickly.
@mm2270 thanks for this version do you need to add an ```
exit 0
```
if [ "$rv" == "1" ]; then
echo "User said OK"
exit
fi
@jhbush1973 - It depends. Since my message only has an "OK" button, I'm not particularly concerned about whether a user clicked it or not. (they would have to click it eventually)
I'd only care if there was more than one button and I needed to take some action or report on what button was clicked.
That said, its usually a good idea to include an exit in a script so we could include exit or exit 0 at the end.
@mm2270 the reason I ask is the script exits 1 and I thought maybe JAMF would see it as a failure.
Heh... I like youze guys solutions better... <snag>
This place is great... any of you scripting whiz types want to assist with this one? It's driving me nuts!
See https://jamfnation.jamfsoftware.com/discussion.html?id=5238 and
https://jamfnation.jamfsoftware.com/discussion.html?id=11226
@jhbush1973 - I see what you mean. That's cocoaDialog reporting that the "OK" button was clicked, not the exit code for the script. I think there's a silent flag in CD that we can throw in there that will make the "1" not show up, but either way, I don't think Casper would see that as a failure since its not the actual exit code. At least I would hope not. That would be just as bad as looking for keywords like "error" ;)
I guess the best test would be to run it from Self Service and see what the end result shows as, as in Failed or Succeeded, etc.
Ok, found it. Had the wrong term though. Its called "--quiet" So just add this to the end of the cocoaDialog section and the "1" will not show up in stdout, in case its a concern. Not sure if the older version of CD has this, but the latest beta does.
Updated code for the cocoaDialog section would look like this-
"$cdPath" msgbox
--title "My IP Addresses"
--text "Details about your Mac"
--informative-text "$MESSAGE"
--button1 " OK "
--icon network **
--quiet**
@mm2270 thanks for pointing that out. One thing I noticed is that it displays the info twice using Self Service. Run by itself the script exits showing the information once. I'm running the beta and I couldn't find that --quiet trigger in the documentation. Good news is that without the --quiet it exits successfully.