Skip to content

Commit

Permalink
Merge pull request #1465 from p-l-/cli-mac
Browse files Browse the repository at this point in the history
cli: add --mac option (ipinfo, scancli, view) and add ivre macdata
  • Loading branch information
p-l- committed Jan 2, 2023
2 parents ca074df + e6201e6 commit 355afe4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ivre/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# This file is part of IVRE.
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
# Copyright 2011 - 2023 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -121,6 +121,7 @@ def __init__(self):
self.argparser.add_argument("--net", metavar="IP/MASK")
self.argparser.add_argument("--ipv4", action="store_true")
self.argparser.add_argument("--ipv6", action="store_true")
self.argparser.add_argument("--mac", metavar="MAC")
self.argparser.add_argument(
"--hassh", metavar="VALUE_OR_HASH", nargs="?", const=False, default=None
)
Expand Down Expand Up @@ -222,6 +223,8 @@ def parse_args(self, args, flt=None):
flt = self.flt_and(flt, self.searchipv4())
if args.ipv6:
flt = self.flt_and(flt, self.searchipv6())
if args.mac is not None:
flt = self.flt_and(flt, self.searchmac(args.mac))
if args.hassh is not None:
flt = self.flt_and(
flt,
Expand Down
3 changes: 2 additions & 1 deletion ivre/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env python

# This file is part of IVRE.
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
# Copyright 2011 - 2023 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -37,6 +37,7 @@
"ipinfo",
"iphost",
"localscan",
"macdata",
"macinfo",
"p0f2db",
"passiverecon2db",
Expand Down
60 changes: 60 additions & 0 deletions ivre/tools/macdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#! /usr/bin/env python

# This file is part of IVRE.
# Copyright 2011 - 2023 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IVRE is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IVRE. If not, see <http://www.gnu.org/licenses/>.


"""This tool can be used to query manufacturers for MAC addresses.
"""


import json
from argparse import ArgumentParser
from sys import stdout

from ivre import utils


def main() -> None:
parser = ArgumentParser(description=__doc__)
parser.add_argument("--json", "-j", action="store_true", help="Output JSON data.")
parser.add_argument(
"mac",
nargs="*",
metavar="MAC",
help="Display manufacturers for specified MAC addresses.",
)
args = parser.parse_args()
for addr in args.mac:
info = utils.mac2manuf(addr)
if args.json:
res = {"addr": addr}
if info:
if isinstance(info, tuple):
if info[0]:
res["manufacturer_code"] = info[0]
if info[1:] and info[1]:
res["manufacturer_name"] = info[1]
else:
res["manufacturer_name"] = info
json.dump(res, stdout)
print()
else:
if isinstance(info, tuple):
print(f"{addr} {' / '.join(i for i in info if i)}")
else:
print(f"{addr} {info}")

0 comments on commit 355afe4

Please sign in to comment.