Skip to main content
Answer

Retrieve external IP address in extension attribute

  • April 10, 2015
  • 7 replies
  • 38 views

Forum|alt.badge.img+12
  • Valued Contributor

Hi all

Can anyone advise me how to create an extension attribute that will record the result of the command curl ifconfig.me

Many thanks
Andy

Best answer by davidacland

You need to set it to be script populated and use:

result=$(curl ifconfig.me)
echo "<result>$result</result>"

I thought the public IP address was in the inventory anyway?

7 replies

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • Answer
  • April 10, 2015

You need to set it to be script populated and use:

result=$(curl ifconfig.me)
echo "<result>$result</result>"

I thought the public IP address was in the inventory anyway?


kitzy
Forum|alt.badge.img+14
  • Valued Contributor
  • April 10, 2015

Hi @May,

Give this a try.

#!/bin/sh
externalIP=$(curl ifconfig.me)
echo "<result>$externalIP</result>"
exit 0

EDIT: @davidacland beat me to it!


Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • April 10, 2015

@davidacland @kitzy

The inventory only shows the Macs ip address and the IP address of our firewall (when the machine is outside our network)

Thank you!
Andy


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • April 10, 2015

@May I think there's a way to set up the JSS to report the actual external IP address of the client, and not the firewall by adjusting something on the JSS, but it escapes me now. Been a long time since I did it or learned about it now.
Because the JSS should be reporting this natively if set up correctly, which would mean an EA for this isn't necessary. That site for me is horribly slow. It can take upwards of 10-12 seconds for a response to come back even from curl. It might just be our company network though.


davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • April 10, 2015

It should be in the tomcat settings:

Enable Remote IP Valve
Ensure that the JSS resolves originating IP addresses instead of apparent client IP addresses when behind a load balancer


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • April 10, 2015

@davidacland Thanks, that's what I was thinking of. Yes, if that's enabled, the IP address should get resolved from the client and not the load balancer.


Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • April 10, 2015

Thanks @davidacland @mm2270

I'll give this a whirl and report back

Cheers again!
Andy