Last active
April 14, 2020 14:59
-
-
Save EscVector/683a2488b82c59db6a2f0d3d9fa80acf to your computer and use it in GitHub Desktop.
Return Public IP Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source https://stackoverflow.com/questions/2311510/getting-a-machines-external-ip-address-with-python | |
#### script #### | |
#Returns ip4 | |
curl 'https://api6.ipify.org?format=json' | |
curl 'https://api.ipify.org?format=json' | |
#### Python #### | |
import os | |
import urllib2 | |
def check_in(): | |
fqn = os.uname()[1] | |
ext_ip = urllib2.urlopen('http://whatismyip.org').read() | |
print ("Asset: %s " % fqn, "Checking in from IP#: %s " % ext_ip) | |
import urllib.request | |
external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8') | |
import miniupnpc | |
u = miniupnpc.UPnP() | |
u.discoverdelay = 200 | |
u.discover() | |
u.selectigd() | |
print('external ip address: {}'.format(u.externalipaddress())) | |
import requests | |
f = requests.request('GET', 'http://myip.dnsomatic.com') | |
ip = f.text | |
import requests | |
ip = requests.get('https://checkip.amazonaws.com').text.strip() | |
#### URL LIST #### | |
https://checkip.amazonaws.com | |
http://myip.dnsomatic.com | |
https://ident.me | |
https://api.ipify.org | |
################################################################### | |
### TERRAFORM EXAMPLE | |
data "http" "example" { | |
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform" | |
# Optional request headers | |
request_headers = { | |
Accept = "application/json" | |
} | |
} | |
output "example_header" { | |
value = ["${data.http.example.response_headers}"] | |
} | |
output "example_body" { | |
value = ["${data.http.example.body}"] | |
} | |
############################# | |
/* | |
http://myip.dnsomatic.com | |
https://ident.me | |
https://api.ipify.org | |
http://ipv4.icanhazip.com | |
https://checkip.amazonaws.com | |
*/ | |
/* | |
data "http" "public_ip" { | |
url = "https://checkip.amazonaws.com" | |
} | |
data "http" "ip1" { | |
url = "http://myip.dnsomatic.com" | |
} | |
output "public_ip1_data" { | |
value = ["${data.http.ip1.body}"] | |
} | |
output "public_ip_headers" { | |
value = ["${data.http.ip1.response_headers}"] | |
} | |
*/ | |
################################### | |
data "http" "ip2" { | |
url = "https://ident.me" | |
} | |
output "public_ip2_data" { | |
value = ["${data.http.ip2.body}"] | |
} | |
data "http" "ip3" { | |
url = "https://api.ipify.org" | |
} | |
output "public_ip3_data" { | |
value = ["${data.http.ip3.body}"] | |
} | |
data "http" "ip4" { | |
url = "http://ipv4.icanhazip.com" | |
} | |
output "public_ip4_data" { | |
value = ["${data.http.ip4.body}"] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment