This sript simply pulls your IP address from a secure php script located on a webserver somewhere on the internet. It then talks to the Amazon AWS EC2 API to update a rule in one of your security groups with your new external IP address. If you have any questions, feel free to email me on opensource [at] emiscience.com
0.0.1
You will need to have the followin installed and workint up before this script will work properly.
- Amazon Web Services] Amazon Web Services Account
- Amazon Web Services CLI Tools - Command line tools for Amazon Web Services * n.b. if you are using OSX follow the Starting Amazon EC2 with Mac OS X guide to install the EC2 tools. I can confirm this works up to and including OSX 10.9 Mavericks.
- Separate security group for use with this script
- Copy the script to somewhere with a websites root directory (it can be in a subdirectory too)
- Permissions are not important
- Edit the script and set the
$secureAgent
variable. Use alphanumeric characters [a-Z][0-0]Try to make it fairly long and note it down, you will need it again. - test the script with
curl -A "stringxN" http://www.foo.com/ipecho.php
- string = the string you created in step 3
This should only return an IP address with no other text..This means that it's working.
- Copy the script to a location of your choice. I suggest somewhere which is in your path environment
- Change the value of
ipechoURL
to be the full URL of the ipecho.php script. e.g. http://www.foo.com/ipecho.php - Change the value of
ec2SecurityGroupID
to match the security group that you intend to use with this script.Please ensure that you use this script with a SEPARATE security group. This will avert the danger of deleting things that shouldnt be deleted
- Change the value of
secureAgent
so that it matches the value of the $secureAgent string in ipecho.php - Make the script executable.
chmod +x ec2-dynamicip.sh
To use the script you only have to exectute it. Version 0.0.1 has no command line arguements.
- Get the script to deal with NO existing rules
- Have a menu rather than a yes/no wizard so there is a greater choice of things to do
- Have command line arguements to make it more scriptable
Below is a screenshot of iTerm (Mac OSX)of me showing you before running the ec2-dynamicip.sh script and after. Before the script, I renewed my DHCP lease getting my another dynamic IP from the ISP (i.e. it's not been authorised to access the example internal server I set up). I then ran the script, agreed to both reauthorising the OLD IP, then agreed to authorising the NEW IP...
Finally, presto, I can now ping the server.
GNU GENERAL PUBLIC LICENS Version 3
have fun and feel free to contribute! EMI Science wouldn't be where it is today without the opensource community and therefor support it fully.
Thankyou - Adrian Sluijters - Managing Director