Created
March 23, 2017 21:56
-
-
Save andrewgross/14ff8c5af41521cdb8ea7c0320578713 to your computer and use it in GitHub Desktop.
CLI App that takes an HTTP address with a host similar to ip-10-32-9-122.ec2.internal and puts in your mac clipboard the HTTP address with the host converted to an IP address.
This file contains 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
import cmd | |
from urlparse import urlparse | |
import sys | |
import re | |
import subprocess | |
def write_to_clipboard(output): | |
process = subprocess.Popen( | |
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE) | |
process.communicate(output.encode('utf-8')) | |
def convert(url): | |
parsed = urlparse(url) | |
host = parsed.hostname | |
result = re.search(r'ip-(?P<ip1>\d+)-(?P<ip2>\d+)-(?P<ip3>\d+)-(?P<ip4>\d+).ec2.internal', host) | |
address = ".".join([result.groupdict()['ip1'], result.groupdict()['ip2'], result.groupdict()['ip3'], result.groupdict()['ip4']]) | |
write_to_clipboard("{}://{}:{}{}".format(parsed.scheme, address, parsed.port, parsed.path)) | |
class Repeater(cmd.Cmd, object): | |
def __init__(self): | |
super(Repeater, self).__init__() | |
self.prompt = "> " | |
def do_exit(self, line): | |
return True | |
def help_exit(self): | |
print_help("""usage: exit | |
Exit S3Browser | |
""") | |
def default(self, line): | |
convert(line) | |
do_EOF = do_exit | |
if __name__ == "__main__": | |
repeater = Repeater() | |
repeater.cmdloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment