1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-03 13:19:04 +00:00

Replace IP address parsing with functions from ipOps

This commit is contained in:
dmiller
2017-03-14 18:59:12 +00:00
parent cc644955c4
commit f89d7610b0
5 changed files with 27 additions and 49 deletions

View File

@@ -182,7 +182,7 @@ action = function()
local transaction_id = bin.pack("<I", math.random(0, 0x7FFFFFFF))
local request_type = dhcp.request_types["DHCPDISCOVER"]
local ip_address = bin.pack(">I", ipOps.todword("0.0.0.0"))
local ip_address = ipOps.ip_to_str("0.0.0.0")
-- we need to set the flags to broadcast
local request_options, overrides, lease_time = nil, { flags = 0x8000 }, nil

View File

@@ -7,6 +7,7 @@ local string = require "string"
local table = require "table"
local target = require "target"
local unicode = require "unicode"
local ipOps = require "ipOps"
local openssl = stdnse.silent_require "openssl"
@@ -135,15 +136,10 @@ local parseHello = function(data)
-- Host ID (MAC Address)
mac = get_mac_addr(v:sub(1,6))
elseif t == 0x08 then
ipv6 = string.format(
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
v:byte(1), v:byte(2), v:byte(3), v:byte(4),
v:byte(5), v:byte(6), v:byte(7), v:byte(8),
v:byte(9), v:byte(10), v:byte(11), v:byte(12),
v:byte(13), v:byte(14), v:byte(15), v:byte(16))
ipv6 = ipOps.str_to_ip(v:sub(1,16))
elseif t == 0x07 then
-- IPv4 address
ipv4 = string.format("%d.%d.%d.%d",v:byte(1),v:byte(2),v:byte(3),v:byte(4)), mac
ipv4 = ipOps.str_to_ip(v:sub(1,4))
-- Machine Name (Hostname)
elseif t == 0x0f then

View File

@@ -1,4 +1,5 @@
local bin = require "bin"
local ipOps = require "ipOps"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
@@ -117,15 +118,8 @@ local function getservers(host, port, q3protocol)
local servers = {}
for _, value in ipairs(pieces) do
local parts = {bin.unpack("CCCC>S", value)}
if #parts > 5 then
local o1 = parts[2]
local o2 = parts[3]
local o3 = parts[4]
local o4 = parts[5]
local p = parts[6]
table.insert(servers, {string.format("%d.%d.%d.%d", o1, o2, o3, o4), p})
end
local ip, port = string.unpack("c4 >I2", value)
table.insert(servers, {ipOps.str_to_ip(ip), port})
end
socket:close()
return servers