Forum Discussion

Antony_Hawkins's avatar
7 years ago

What Is My IP as found from a Google search

This is just another Google results scrape like my exchange rate tracker (a href="https://communities.logicmonitor.com/topic/1624-ridiculously-simple-currency-exchange-rate-monitor/" rel="">https://communities.logicmonitor.com/topic/1624-ridiculously-simple-currency-exchange-rate-monitor/), so it's more a couple of examples of how that can be done, than a particularly useful set of metrics for enterprises with fixed IPs.

I only built these because my home very-nearly-static IP changed the other day after my ISP did some work locally, so my carefully-selected whitelisting to access another cloud service from home failed. Boo hiss.

Note that these LogicModules will always be run by the collector, so the result will be whatever Google determine's your collector's public IP to be, regardless of which device you associate the LogicModules with.

For this reason they both have AppliesTo of hasCategory("collector") which I recommend you don't change.

Anyway... there's a straight and simple Webpage collection DataSource:

v1.0.0: KTFNWP

This calls "https://www.google.com/search?q=what+is+my+ip" and has four datapoints, each of which pulls one octet via a regex of the resultant page body, using e.g.:

(\d+)\.\d+\.\d+\.\d+.*Your public IP address

This is possible because Google will do the lookup for you and present the data in a consistent format; a brief check of the page source code and a visit to regex101.com is all that's then needed to determine suitable regexes:


IP address is not model's own.

This gives you one metric and one graph line per octet and you can set delta alerting thresholds if you wish.

ConfigSource:

Additionally, if you have LM Config, there's a ConfigSource that does much the same but (obviously) writes the result to a config, with the single line output "Google says my public IP address is 12.34.123.123", the IP again be regexed out of the Google response.

This will alert on any change.

ConfigSource v1.0.0: 3G9C63

 

7 Replies

Replies have been turned off for this discussion
  • Hey Antony, this is great however for some reason no matter what host\customer I point this DataSource to I get the same IP address. Do you know if there has been any change in how google returns the values?

    Also, turns out the configsource is under review too, any ideas when it will be approved?

    Thank you!

  • @wanabeninja@helient it should be out out of the review holding cell now.

    I can't imagine Google would have done anything to break this. It works for me. Those hosts/customers aren't behind the same NAT gateway, are they? Or using a shared proxy?

    Have they tried other sites that do this to see if they get the same result? I was always partial to ifconfig.me, and ipchicken.com, though please don't take that as an official LM endorsement :).

  • Thank you Michael for taking interest into this post.

    As for the configsource, yes I just tried again and it's working, great success!

    As for the getting the same Ip address for different host/customer, I've simply been staring at this far too long trying to get it to poll a non-collector. I've also tried https://bot.whatismyipaddress.com/ thinking maybe it was google end but nope, it's simply how this module is built and will ALWAYS look at the collector. 

    I suppose the next request if possible is if we can allow this same code to point to any host and not just a collector, fingers crossed. 

  • Hi, as you've found (and as commented in the original post), DataSource scripts are run by the collector so you'll always get the collector's (or its network's) external IP.

    For a per-device result you could create a remote Powershell script for Windows devices and an SSH script for Linux devices that connected to the device assigned, and ran a suitable http request on the device, and grabbed that output. At that point the result would be for the monitored device rather than the collector, although of course if all the devices were on one network that only had one public-facing IP, that IP will still be the value returned from a Google search.

  • Great stuff, happy to have been a help.

    Feel free to call out our Support Engineer by name, so I can give them some kudos too!

  • 17 minutes ago, Antony Hawkins said:

    Great stuff, happy to have been a help.

    Feel free to call out our Support Engineer by name, so I can give them some kudos too!

    Mr. Imdad Salih