This code seems to rely on IP ranges and whois lookups, which won't work if you're running on a network / VPC that has no internet access<p>Some clouds provide a metadata api accessible via a link-local address. These are accessibly regardless of what network your instance is in.<p>AWS Metadata API: <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html" rel="nofollow">http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-insta...</a><p>GCE Metadata API: <a href="https://cloud.google.com/compute/docs/metadata" rel="nofollow">https://cloud.google.com/compute/docs/metadata</a><p>Azure Metadata API: <a href="https://azure.microsoft.com/en-us/blog/what-just-happened-to-my-vm-in-vm-metadata-service/" rel="nofollow">https://azure.microsoft.com/en-us/blog/what-just-happened-to...</a><p>This library only appears to support detecting AWS/GCE/Azure, so perhaps trying URLs in each metadata API with no / minimal timeout is a more robust way of accomplishing this instead of relying on whois, and could provide the same functionality as is currently supported in the library.<p>The downside of this approach is that maybe some clouds/VPS's don't have metadata APIs accessible in this manner. Maybe this doesn't work for some more obscure services, if you want to be super comprehensive.
See also: The Hurricane Electric BGP Toolkit shows the ISP based on the AS number from which the IP address is announced: <a href="http://bgp.he.net/" rel="nofollow">http://bgp.he.net/</a><p>Example: <a href="http://bgp.he.net/ip/104.196.27.39" rel="nofollow">http://bgp.he.net/ip/104.196.27.39</a>