Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e931344

Browse files
committed
More elegant implementation for --random-agent
1 parent 9456dc6 commit e931344

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

lib/core/option.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import inspect
1111
import logging
1212
import os
13+
import random
1314
import re
1415
import socket
1516
import string
@@ -45,7 +46,6 @@
4546
from lib.core.common import parseTargetDirect
4647
from lib.core.common import parseTargetUrl
4748
from lib.core.common import paths
48-
from lib.core.common import randomRange
4949
from lib.core.common import randomStr
5050
from lib.core.common import readCachedFileContent
5151
from lib.core.common import readInput
@@ -1331,15 +1331,7 @@ def _setHTTPUserAgent():
13311331
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, _defaultHTTPUserAgent()))
13321332
return
13331333

1334-
count = len(kb.userAgents)
1335-
1336-
if count == 1:
1337-
userAgent = kb.userAgents[0]
1338-
else:
1339-
userAgent = kb.userAgents[randomRange(stop=count - 1)]
1340-
1341-
userAgent = sanitizeStr(userAgent)
1342-
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, userAgent))
1334+
userAgent = random.sample(kb.userAgents or [_defaultHTTPUserAgent()], 1)[0]
13431335

13441336
infoMsg = "fetched random HTTP User-Agent header from "
13451337
infoMsg += "file '%s': %s" % (paths.USER_AGENTS, userAgent)

0 commit comments

Comments
 (0)