Retrieve external IP address in extension attribute

May
Contributor III

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

2 ACCEPTED SOLUTIONS

davidacland
Honored Contributor II
Honored Contributor II

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?

View solution in original post

kitzy
Contributor III

Hi @May,

Give this a try.

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

EDIT: @davidacland beat me to it!

View solution in original post

7 REPLIES 7

davidacland
Honored Contributor II
Honored Contributor II

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
Contributor III

Hi @May,

Give this a try.

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

EDIT: @davidacland beat me to it!

May
Contributor III

@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
Legendary Contributor III

@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
Honored Contributor II
Honored Contributor II

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
Legendary Contributor III

@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.

May
Contributor III

Thanks @davidacland @mm2270

I'll give this a whirl and report back

Cheers again!
Andy