Last active
November 22, 2018 02:53
-
-
Save Justsoos/4fb7d5af0ddf86d757f9efeb6bb570b3 to your computer and use it in GitHub Desktop.
Revisions
-
Justsoos revised this gist
Nov 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ def ssip(ip): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('ip',nargs='?',default='') args = parser.parse_args() ip = args.ip -
Justsoos revised this gist
Oct 31, 2018 . 1 changed file with 18 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ # if puzzled by "from html_table_parser import HTMLTableParser, ImportError: cannot import name 'HTMLTableParser'" # delete the dir of "python3/dist-packages/html_table_parser" manully and then reinstall, it comes from a bug of pip import re import requests import argparse # import logging @@ -26,6 +27,22 @@ def ssip(ip): break p = HTMLTableParser() p.feed(html.text) rtb_html = re.search(r'"(https://ip\.rtbasia\.com[^"]+?)"', html.text) if rtb_html: for i in range(1,3): iframe = sess.get(rtb_html.group(1), headers=headers) if iframe.status_code==200: break rtb_text = re.search(r'>([^&>]+?) ([^&]+?) ([^<]+?)<', iframe.text) if rtb_text.group(3): rtb = ''.join(rtb_text.group(1,2,3)) else: rtb = 'rtb error {}'.format(rtb_text.group(0)) else: rtb = 'rtb html error' p.tables[-1][1] = [rtb] for y in p.tables: t = PrettyTable(y.pop(0)) for val in y: @@ -39,4 +56,4 @@ def ssip(ip): args = parser.parse_args() ip = args.ip ssip(ip) -
Justsoos created this gist
Oct 29, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #!/usr/bin/env python3 # IMPORTANT! install the correct package: pip3 install html-table-parser-python3 # if puzzled by "from html_table_parser import HTMLTableParser, ImportError: cannot import name 'HTMLTableParser'" # delete the dir of "python3/dist-packages/html_table_parser" manully and then reinstall, it comes from a bug of pip import requests import argparse # import logging from requests.adapters import HTTPAdapter from html_table_parser import HTMLTableParser from prettytable import PrettyTable sess = requests.Session() sess.mount('', HTTPAdapter(max_retries=5)) headers = {'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Mobile Safari/537.36'} # logging.getLogger().setLevel(logging.DEBUG) # logging.debug('') def ssip(ip): ref_url = 'https://www.ipip.net/ip.html' url = ref_url sess.headers.update({'referer': ref_url}) for i in range(1,3): html = sess.post(url, headers=headers, allow_redirects=False, data={'ip':ip}) if html.status_code==200: break p = HTMLTableParser() p.feed(html.text) for y in p.tables: t = PrettyTable(y.pop(0)) for val in y: val = [s.replace('\r', '') for s in val] t.add_row(val) print(t) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('ip') args = parser.parse_args() ip = args.ip ssip(ip)