mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Removed packet.hextobin and packet.bintohex. Both are unnecessary
with the struct (bin) library available:
function hextobin(str) return bin.pack("H", str) end
function bintohex(str) return bin.unpack("H", str) end
Also removed a commented copy that was in the sniffer-detect.nse script.
This commit is contained in:
@@ -580,43 +580,3 @@ function Packet:tcp_lookup_link()
|
||||
end
|
||||
return string.format("unknown-%i", self.tcp_opt_mtu)
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- UTILS
|
||||
|
||||
--- Convert a byte string to a hex string.
|
||||
-- @param str Byte string.
|
||||
-- @return Hex string.
|
||||
function bintohex(str)
|
||||
local b = ""
|
||||
if not str then -- nil
|
||||
return ""
|
||||
end
|
||||
for c in string.gmatch(str, ".") do
|
||||
b = string.format('%s%02x',b, string.byte(c))
|
||||
end
|
||||
return b
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Convert a hex string to a byte string.
|
||||
--
|
||||
-- Only bytes <code>[a-f0-9A-F]</code> from input are interpreted. The rest is
|
||||
-- ignored. The number of interpreted bytes must be even.
|
||||
-- @param str Hex string.
|
||||
-- @return Byte string.
|
||||
-- @usage
|
||||
-- hextobin("20 20 20") --> " "
|
||||
-- hextobin("414243") --> "ABC"
|
||||
-- hextobin("\\41\\42\\43") --> "ABC"
|
||||
-- hextobin(" 41 42 43 ") --> "ABC"
|
||||
function hextobin(str)
|
||||
return (string.gsub(str, "%X*(%x%x)%X*", function(a)
|
||||
return string.char(tonumber(a, 16));
|
||||
end));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -24,16 +24,6 @@ hostrule = function(host, port)
|
||||
nmap.get_interface_link(host.interface) == 'ethernet'
|
||||
end
|
||||
|
||||
--[[
|
||||
function bintohex(str)
|
||||
local b = ""
|
||||
for c in string.gmatch(str, ".") do
|
||||
b = string.format('%s%02x',b, string.byte(c))
|
||||
end
|
||||
return b
|
||||
end
|
||||
--]]
|
||||
|
||||
callback = function(packetsz, layer2, layer3)
|
||||
return string.sub(layer2, 0, 12)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user