Advertisement
Guest User

Python Random User-Agent Generator

a guest
Oct 15th, 2012
2,533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. # Random User-Agent Generator
  2. # Version 1.0.0
  3. # Coded by InvisibleMan in Python
  4. # Download : N/A
  5. # File     : user.py
  6.  
  7. #IMPORTS
  8. import random
  9.  
  10. #GET USER-AGENT
  11. def getUserAgent():
  12.     platform = random.choice(['Macintosh', 'Windows', 'X11'])
  13.     if platform == 'Macintosh':
  14.         os  = random.choice(['68K', 'PPC'])
  15.     elif platform == 'Windows':
  16.         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'])
  17.     elif platform == 'X11':
  18.         os  = random.choice(['Linux i686', 'Linux x86_64'])
  19.     browser = random.choice(['chrome', 'firefox', 'ie'])
  20.     if browser == 'chrome':
  21.         webkit = str(random.randint(500, 599))
  22.         version = str(random.randint(0, 24)) + '.0' + str(random.randint(0, 1500)) + '.' + str(random.randint(0, 999))
  23.         return 'Mozilla/5.0 (' + os + ') AppleWebKit/' + webkit + '.0 (KHTML, live Gecko) Chrome/' + version + ' Safari/' + webkit
  24.     elif browser == 'firefox':
  25.         year = str(random.randint(2000, 2012))
  26.         month = random.randint(1, 12)
  27.         if month < 10:
  28.             month = '0' + str(month)
  29.         else:
  30.             month = str(month)
  31.         day = random.randint(1, 30)
  32.         if day < 10:
  33.             day = '0' + str(day)
  34.         else:
  35.             day = str(day)
  36.         gecko = year + month + day
  37.         version = random.choice(['1.0', '2.0', '3.0', '4.0', '5.0', '6.0', '7.0', '8.0', '9.0', '10.0', '11.0', '12.0', '13.0', '14.0', '15.0'])
  38.         return 'Mozilla/5.0 (' + os + '; rv:' + version + ') Gecko/' + gecko + ' Firefox/' + version
  39.     elif browser == 'ie':
  40.         version = str(random.randint(1, 10)) + '.0'
  41.         engine = str(random.randint(1, 5)) + '.0'
  42.         option = random.choice([True, False])
  43.         if option == True:
  44.             token = random.choice(['.NET CLR', 'SV1', 'Tablet PC', 'Win64; IA64', 'Win64; x64', 'WOW64']) + '; '
  45.         elif option == False:
  46.             token = ''
  47.         return 'Mozilla/5.0 (compatible; MSIE ' + version + '; ' + os + '; ' + token + 'Trident/' + engine + ')'
  48.  
  49. while True:
  50.     print getUserAgent()
  51.     raw_input('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement