Setting the user agent pragmatically

There are some packet filtering products that block requests using Nmap's default HTTP user agent. You can use a different user agent value by setting the argument http.useragent:

$ nmap -p80 --script http-sqli-finder --script-args http.useragent="Mozilla 42" <target>  

To set the user agent in your NSE script, you can pass the header field, as follows:

   options = {header={}}    options['header']['User-Agent'] = "Mozilla/9.1 (compatible; Windows       NT 5.0 build 1420;)"    local req = http.get(host, port, uri, options) 

Get Nmap: Network Exploration and Security Auditing Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.