loldongs

PyAgent User Agent Generator

Sep 27th, 2013
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. # PyAgent User Agent Generator
  2. # Version 1.0.0
  3. # Coded by BlackMan in Python 2.7.5
  4. # Download : N/A
  5. # File     : pyagent.py
  6.  
  7. #IMPORTS
  8. import datetime
  9. import random
  10.  
  11. #GET USER-AGENT
  12. def getUserAgent():
  13.     platform = random.choice(['Macintosh', 'Windows', 'X11'])
  14.     if platform == 'Macintosh':
  15.         os  = random.choice(['68K', 'PPC'])
  16.     elif platform == 'Windows':
  17.         os  = random.choice(['Win3.11', 'WinNT3.51', 'WinNT4.0', 'Windows NT 5.0', 'Windows NT 5.1', 'Windows NT 5.2', 'Windows NT 6.0', 'Windows NT 6.1', 'Windows NT 6.2', 'Win95', 'Win98', 'Win 9x 4.90', 'WindowsCE'])
  18.     elif platform == 'X11':
  19.         os  = random.choice(['Linux i686', 'Linux x86_64'])
  20.     browser = random.choice(['chrome', 'firefox', 'ie'])
  21.     if browser == 'chrome':
  22.         webkit = str(random.randint(500, 599))
  23.         version = str(random.randint(0, 28)) + '.0' + str(random.randint(0, 1500)) + '.' + str(random.randint(0, 999))
  24.         return 'Mozilla/5.0 (' + os + ') AppleWebKit/' + webkit + '.0 (KHTML, like Gecko) Chrome/' + version + ' Safari/' + webkit
  25.     elif browser == 'firefox':
  26.         currentYear = datetime.date.today().year
  27.         year = str(random.randint(2000, currentYear))
  28.         month = random.randint(1, 12)
  29.         if month < 10:
  30.             month = '0' + str(month)
  31.         else:
  32.             month = str(month)
  33.         day = random.randint(1, 30)
  34.         if day < 10:
  35.             day = '0' + str(day)
  36.         else:
  37.             day = str(day)
  38.         gecko = year + month + day
  39.         version = str(random.randint(1, 21)) + '.0'
  40.         return 'Mozilla/5.0 (' + os + '; rv:' + version + ') Gecko/' + gecko + ' Firefox/' + version
  41.     elif browser == 'ie':
  42.         version = str(random.randint(1, 10)) + '.0'
  43.         engine = str(random.randint(1, 5)) + '.0'
  44.         option = random.choice([True, False])
  45.         if option == True:
  46.             token = random.choice(['.NET CLR', 'SV1', 'Tablet PC', 'Win64; IA64', 'Win64; x64', 'WOW64']) + '; '
  47.         else:
  48.             token = ''
  49.         return 'Mozilla/5.0 (compatible; MSIE ' + version + '; ' + os + '; ' + token + 'Trident/' + engine + ')'
Add Comment
Please, Sign In to add comment