Skip to content

Instantly share code, notes, and snippets.

@pronto
Last active April 24, 2018 17:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pronto/af5564406afb1615a7feecea0b721714 to your computer and use it in GitHub Desktop.
Save pronto/af5564406afb1615a7feecea0b721714 to your computer and use it in GitHub Desktop.
find where url shorteners go
#!/usr/bin/env python3
#(works for 2.7 as well)
#todo: add support for <script>window.location='nsa.gov'<script>
import requests
import sys
def get_loc(url):
try:
h=requests.head(url).headers['location']
return h
except KeyError:
return 'END'
urlcnt=len(sys.argv)-1
if urlcnt == 0:
print('please enter in a url')
sys.exit(1)
headloop = get_loc(sys.argv[1])
while headloop != 'END':
print(headloop)
headloop = get_loc(headloop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment