Skip to content

Commit

Permalink
Merge pull request #37 from emtunc/dev
Browse files Browse the repository at this point in the history
automatically obtain latest user_agent header
  • Loading branch information
emtunc authored Jan 29, 2019
2 parents 7f704ff + f7b6acd commit 0c15149
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions SlackPirate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from typing import List
from multiprocessing import Process, Queue
from constants import getUserAgent
from constants import get_user_agent


#############
Expand Down Expand Up @@ -761,7 +761,7 @@ def file_cleanup(input_file, scan_context: ScanningContext):
parser.add_argument('--no-file-download', dest='file_download', action='store_false',
help='disable downloading of files from the Workspace')
parser.add_argument('--version', action='version',
version='SlackPirate.py v0.10. Developed by Mikail Tunç (@emtunc) with contributions from '
version='SlackPirate.py v0.11. Developed by Mikail Tunç (@emtunc) with contributions from '
'the amazing community! https://github.com/emtunc/SlackPirate/graphs/contributors')
"""
Even with "argument_default=None" in the constructor, all flags were False, so we explicitly set every flag to None
Expand All @@ -771,7 +771,7 @@ def file_cleanup(input_file, scan_context: ScanningContext):
private_key_scan=None, link_scan=None, file_download=None, pinned_message_scan=None)
args = parser.parse_args()

selected_agent = getUserAgent()
selected_agent = get_user_agent()

if args.cookie is None and args.token is None: # Must provide one or the other
print(termcolor.colored("No arguments passed. Run SlackPirate.py --help ", "white", "on_red"))
Expand Down
15 changes: 13 additions & 2 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import random
import requests

user_agents = [
"Mozilla/5.0 (Windows NT 6.2; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0",
Expand All @@ -29,5 +30,15 @@
]


def getUserAgent():
return random.choice(user_agents)
def get_user_agent():
operating_systems = ['windows', 'osx']
browsers = ['chrome', 'firefox']
try:
user_agent = requests.get(
"https://api.user-agent.io/?browser=" + random.choice(browsers) + "&os=" + random.choice(operating_systems))
if user_agent.status_code == 200 and "Mozilla" in user_agent.text:
return user_agent.text
else:
return random.choice(user_agents)
except requests.exceptions.RequestException:
return random.choice(user_agents)

0 comments on commit 0c15149

Please sign in to comment.