3 Commits

6 changed files with 228 additions and 127 deletions
Split View
  1. +1
    -101
      .gitignore
  2. +14
    -0
      Pipfile
  3. +187
    -0
      Pipfile.lock
  4. +6
    -4
      README.md
  5. +20
    -20
      aws-sg-ip-updater.py
  6. +0
    -2
      requirements.txt

+ 1
- 101
.gitignore View File

@ -1,101 +1 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.vscode/

+ 14
- 0
Pipfile View File

@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
boto3 = "*"
requests = "*"
[dev-packages]
pylint = "*"
[requires]
python_version = "3.8"

+ 187
- 0
Pipfile.lock View File

@ -0,0 +1,187 @@
{
"_meta": {
"hash": {
"sha256": "236b11790eb3ec11c1c41acea3166f23066beba24bb101b9752876c29f1b0547"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.8"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"boto3": {
"hashes": [
"sha256:3f26aad4c6b238055d17fd662620284ffb4ced542ed9a2f7f9df65d97a3f1190",
"sha256:47151ed571c316458f4931cd2422995ba0c9f6818c5df7d75f49fc845208e42e"
],
"index": "pypi",
"version": "==1.16.56"
},
"botocore": {
"hashes": [
"sha256:01496e4c2c06aab79689f2c345a0e2cceb5fe1da7858a7e7df189bcf97703223",
"sha256:a37d073c2f166753cc3799e77d87d4096e24433fcca5e7c8cc8e77e5dbfe60e9"
],
"version": "==1.19.56"
},
"certifi": {
"hashes": [
"sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c",
"sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830"
],
"version": "==2020.12.5"
},
"chardet": {
"hashes": [
"sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa",
"sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==4.0.0"
},
"idna": {
"hashes": [
"sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
"sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==2.10"
},
"jmespath": {
"hashes": [
"sha256:b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9",
"sha256:cdf6525904cc597730141d61b36f2e4b8ecc257c420fa2f4549bac2c2d0cb72f"
],
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==0.10.0"
},
"python-dateutil": {
"hashes": [
"sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c",
"sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==2.8.1"
},
"requests": {
"hashes": [
"sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804",
"sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"
],
"index": "pypi",
"version": "==2.25.1"
},
"s3transfer": {
"hashes": [
"sha256:1e28620e5b444652ed752cf87c7e0cb15b0e578972568c6609f0f18212f259ed",
"sha256:7fdddb4f22275cf1d32129e21f056337fd2a80b6ccef1664528145b72c49e6d2"
],
"version": "==0.3.4"
},
"six": {
"hashes": [
"sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259",
"sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.15.0"
},
"urllib3": {
"hashes": [
"sha256:19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08",
"sha256:d8ff90d979214d7b4f8ce956e80f4028fc6860e4431f731ea4a8c08f23f99473"
],
"markers": "python_version != '3.4'",
"version": "==1.26.2"
}
},
"develop": {
"astroid": {
"hashes": [
"sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703",
"sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386"
],
"markers": "python_version >= '3.5'",
"version": "==2.4.2"
},
"isort": {
"hashes": [
"sha256:c729845434366216d320e936b8ad6f9d681aab72dc7cbc2d51bedc3582f3ad1e",
"sha256:fff4f0c04e1825522ce6949973e83110a6e907750cd92d128b0d14aaaadbffdc"
],
"markers": "python_version >= '3.6' and python_version < '4.0'",
"version": "==5.7.0"
},
"lazy-object-proxy": {
"hashes": [
"sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d",
"sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449",
"sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08",
"sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a",
"sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50",
"sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd",
"sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239",
"sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb",
"sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea",
"sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e",
"sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156",
"sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142",
"sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442",
"sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62",
"sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db",
"sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531",
"sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383",
"sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a",
"sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357",
"sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4",
"sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.4.3"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
],
"version": "==0.6.1"
},
"pylint": {
"hashes": [
"sha256:bb4a908c9dadbc3aac18860550e870f58e1a02c9f2c204fdf5693d73be061210",
"sha256:bfe68f020f8a0fece830a22dd4d5dddb4ecc6137db04face4c3420a46a52239f"
],
"index": "pypi",
"version": "==2.6.0"
},
"six": {
"hashes": [
"sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259",
"sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.15.0"
},
"toml": {
"hashes": [
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
"sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
],
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==0.10.2"
},
"wrapt": {
"hashes": [
"sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"
],
"version": "==1.12.1"
}
}
}

+ 6
- 4
README.md View File

@ -3,18 +3,20 @@
A Python application that updates your security group based off of your current IP address.
## Prerequisites
* [AWS CLI](https://aws.amazon.com/cli/) installed and configured with a default profile
* AWS Profile specified has necessary permissions to update an EC2 Security Group
* Python 3.8
* [pipenv](https://pipenv.pypa.io/en/latest/) is used for environment management.
* AWS Profile configured with a default profile specified has necessary permissions to update an EC2 Security Group (you can have this setup without having AWSCLI installed see [HERE](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)
## How do I get set up?
* Run `pip install --upgrade -r requirements.txt` to install the Boto3 & Requirements libraries.
* Run `pipenv install` to install the python requirements listed in Pipefile/Pipfile.lock in a new virtual environment. Make sure to install pipenv from above link before this.
## ToDo
* add in more error handling
* Change response to be a friendly message vs. json output
* Add in functionality to be able to pass in which AWSCLI profile you want to use.
* Add in functionality to be able to pass in which AWSCLI profile you want to use
* add Digital Ocean as a provider
## Details
I frequently use a VPN, especially when on public or unknown Wi-Fi. For this reason I always had to login to the AWS Console anytime I wanted to connect to my EC2 instances to update security groups due to my always changing IP. I decided to write this python script to solve this problem.

+ 20
- 20
aws-sg-ip-updater.py View File

@ -29,7 +29,7 @@ def add_ip(current_ip, sg_id, port, protocol):
ToPort=port,
CidrIp=current_ip
)
print response
print(response)
def remove_ip(current_ip, sg_id, port, protocol):
"""remove current IP from the security group"""
@ -45,28 +45,28 @@ def remove_ip(current_ip, sg_id, port, protocol):
ToPort=port,
CidrIp=current_ip
)
print response
print(response)
# Define the usage of the app
def usage():
"""Prints usage information"""
print
print "AWS Security Group IP Updater"
print
print "Usage: aws-sg-ip-updater.py -s sg-abc123456"
print " NOTE: This does require the AWSCLI be installed and configured"
print "-h --help - this message"
print "-s --sg_id - id of the security group"
print "-f --profile - profile name to use from AWSCLI config"
print "-p --port - port for rule"
print "-t --protocol - networking protcal for the rule"
print "-r --remove - remove current IP from security group"
print
print
print "Examples:"
print "aws-sg-ip-updater.py --sg_id sg-abc123456"
print "aws-sg-ip-updater.py --sg_id sg-abc123456 --port 22 --protocol tcp"
print
print()
print( "AWS Security Group IP Updater")
print()
print( "Usage: aws-sg-ip-updater.py -s sg-abc123456")
print( " NOTE: This does require the AWSCLI be installed and configured")
print( "-h --help - this message")
print( "-s --sg_id - id of the security group")
print( "-f --profile - profile name to use from AWSCLI config")
print( "-p --port - port for rule")
print( "-t --protocol - networking protcal for the rule")
print( "-r --remove - remove current IP from security group")
print()
print()
print( "Examples:")
print( "aws-sg-ip-updater.py --sg_id sg-abc123456")
print( "aws-sg-ip-updater.py --sg_id sg-abc123456 --port 22 --protocol tcp")
print()
sys.exit(0)
def main():
@ -85,7 +85,7 @@ def main():
["help", "sg_id=", "profile=", "port=", "protocol=","remove"])
except getopt.GetoptError as err:
# print error and help information
print str(err) # will print something like "option -q not recognized"
print(str(err)) # will print something like "option -q not recognized"
usage()
for o, a in opts:


+ 0
- 2
requirements.txt View File

@ -1,2 +0,0 @@
boto3==1.4.4
requests==2.18.1

Loading…
Cancel
Save