Official ipinfo.io Perl library. Running into Non official docker container.
- ipinfo token, you can get from https://ipinfo.io/account
- clone project
- create file ipinfo.token contains token as described above
$ cat ipinfo.token
1234567890abcd
-
build test image and run
docker build --build-arg RELEASE_TESTING=yes . -t gkirok/ipinfo:testdocker run -it gkirok/ipinfo:test
-
build image
docker build . -t gkirok/ipinfo:latest
-
run container
- run as web service
docker run -d -v ipinfo.token:/opt/ipinfo.token -p 80:8080 --name ipinfo gkirok/ipinfo:latestcurl localhost/IP_YOU_WANT_TO_DESCRIBE
OR
- run single request
docker run -d -v ipinfo.token:/opt/ipinfo.token -p 80:8080 --name ipinfo gkirok/ipinfo:latest IP_YOU_WANT_TO_DESCRIBE
- run as web service
- aws credentials with full ec2 premissions
- installed Jenkins Pipeline server with configured docker, terraform and ansible
By default ipinfo web server will be deployed as docker container to t2.micro ec2 instance, has been accessed by http to all, and by ssh from jenkins server and user 'access' server.
- docker: build test image - building test image and running unit tests
- docker: build & push image - building deploy image and push it to registry
- terraform: pull & init - pulling terraform image and init project terraform folder
- terraform: plan - create plan for deployed ec2 server and security group
- terraform: apply - deploy ec2 server and security group
- ansible: requirements - install required software as docker
- ansible: deploy - pull new image and redeploy ipinfo container
- result - print ip of deployed server
- ssh connect to your jenkins server and generate private/public keys have been using to connect to ec2 server.
and save it as
~/.ssh/tikaland~/.ssh/tikal.pub - add these credentials parameters to your jenkins server
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- JENKINS_IP
- ACCESS_IP
- ipinfo_token
- private key using to connect to ec2 server by ansible from step 1 ('3276ccf3-13bc-4408-b815-7b07bfd4e972' in Jenkinsfile)
- github credentials
- hub.docker.com credentials
- fork project
- create project in hub.docker.com
- edit Jenkinsfile, commit and push changes
- replace ids of credentials have been configured in step 2.
- update global variables
- create new pipeline with forked project and run it
- go to browser and enter ip of deployed server and ip yuu want to describe
- for example:
http://54.54.54.54/8.8.8.8
- for example:
use Geo::IPinfo;
my $token = "1234567";
# if you have a valid token, use it
my $ipinfo = Geo::IPinfo->new($token);
# or, if you don't have a token, use this:
# my $ipinfo = Geo::IPinfo->new();
# return a hash reference containing all IP related information
my $data = $ipinfo->info("8.8.8.8");
if (defined $data) # valid data returned
{
print "Information about IP 8.8.8.8:\n";
for my $key (sort keys %$data )
{
printf "%10s : %s\n", $key, $data->{$key};
}
print "\n";
}
else # invalid data obtained, show error message
{
print $ipinfo->error_msg . "\n";
}
# retrieve only city information of the IP address
my $city = $ipinfo->field("8.8.8.8", "city");
print "The city of 8.8.8.8 is $city\n";
Information about IP 8.8.8.8:
city : Mountain View
country : US
hostname : google-public-dns-a.google.com
ip : 8.8.8.8
loc : 37.3860,-122.0840
org : AS15169 Google LLC
phone : 650
postal : 94035
region : California
The city of 8.8.8.8 is Mountain View
export RELEASE_TESTING=yes && for i in *.t; do /bin/perl -T $i; done
For details about how to use the library, install it and then run:
perldoc Geo::IPinfo
Make sure ALL tests executed without errors; to do this, run:
$ cd Geo-IPinfo/
$ perl Makefile.PL
$ RELEASE_TESTING=1 make test
In particular, pay attention to the result of the execution of 't/01-usage.t'; to see more detailed information about the execution of this test, run:
$ RELEASE_TESTING=1 prove -bv t/01-usage.t