NSE LIB

Back to library
Unofficial informational Discovery

country_scan

Scan by country.

Ports

Any

Protocols

n/a

Attribution

Dr Claw (upstream: mmpx12/nse-country-scan)

Usage

No example usage is currently available for this script entry.

Example usage has not been added for this script yet.
Script Source Toggle

The full script source is stored with this entry and is hidden by default to keep the page easier to scan.

author = "Dr Claw"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"discovery"}

description = [[
  Scan by country.
]]

local nmap = require "nmap"
local stdnse = require "stdnse"
local target = require "target"
local random_country = false
local country = stdnse.get_script_args("country_scan.country")
local max_ip = stdnse.get_script_args("country_scan.max_ip")
local newtargets = stdnse.get_script_args("country_scan.newtargets")
local function isempty(v)
  return v == nil or v == ''
end

if isempty(country) then
  local arr = {}
  local file = io.open("/usr/share/nmap/nselib/country/country_list.lst", "r")
  for line in file:lines() do
    table.insert(arr, line)
  end
  file:close()
  random_country = true
  country = arr[ math.random( #arr )]:sub(1,2)
end

local country_path = ("/usr/share/nmap/nselib/country/list/" .. country)

local file = io.open("/usr/share/nmap/nselib/country/country_list.lst", "r")

for line in file:lines() do
  if string.match(line, country) then
    country_name = line:sub(4, -1)
    break
  end
end

file:close()

prerule = function()
  if (newtargets ~= 1) then
      print("\n[NSE country scan] error: to add targets run with --script-args 'newtargets'\n")
      return false
  end
  print("\n ------------------")
  print("| NSE country scan |")
  print(" ------------------")
  if random_country == true then
    print("No args passed..")
    print("Scanning random country: " .. country_name)
  else
    print("Scanning: " .. country_name)
  end
  local i = 1
  print("\n")
  local file = io.open(country_path, "r")
  for ip in file:lines() do
    target.add(ip)
    if i == tonumber(max_ip) then
      break
    else
      i = i + 1
    end
  end
  file:close()
end

action = function()
  return "ok"
end

Overview

Imported from the upstream repository mmpx12/nse-country-scan. Scan a whole country with nmap

Installation

git clone https://github.com/mmpx12/nse-country-scan.git
cd nse-country-scan
sudo make

usage

If no argument is pass the script while choose a random country and scan all the ips Argument are:

  • country: “Code of the country in uppercase”>
  • max_ip: “Number of ip range to scan”
  • newtargets “Without nmap can’t add target to queue”
nmap --script country_scan --script-args 'country=LU, max_ip=2'
# This whill scan 2 range of ip and not 2 ip only
# You can see which one with `HEAD -2 /usr/share/nmap/nselib/country/list/LU`

Other ip, script or nmap argument can be pass like:

nmap -sn --script country_scan --script-args 'country=LU, max_ip=2, newtargets' 1.1.1.1

Delete

For deleting this script run:

cd nse-country-scan
sudo make clean