Skip to content

Adding mac address support#1580

Merged
Mzack9999 merged 1 commit intodevfrom
feat-mac-address
Nov 10, 2025
Merged

Adding mac address support#1580
Mzack9999 merged 1 commit intodevfrom
feat-mac-address

Conversation

@Mzack9999
Copy link
Copy Markdown
Member

@Mzack9999 Mzack9999 commented Nov 8, 2025

Lookup private ip mac address via native arp command

Closes #1581

Summary by CodeRabbit

  • New Features
    • Introduced MAC address discovery for identified hosts on private networks using ARP queries
    • MAC addresses now included in JSON and CSV output formats for better host identification
    • Automatic MAC resolution integrated into scan results

@Mzack9999 Mzack9999 self-assigned this Nov 8, 2025
@Mzack9999 Mzack9999 added the Type: Enhancement Most issues will probably ask for additions or changes. label Nov 8, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR implements MAC address lookup functionality for private IP addresses. It adds a MacAddress field to HostResult and Result structs, introduces ARP-based MAC discovery via the GetMacAddress() function, and propagates MAC address data through JSON and CSV output paths using new *WithMac helper functions.

Changes

Cohort / File(s) Change Summary
Core MAC address discovery
pkg/result/results.go
Added MacAddress field to HostResult struct; introduced GetMacAddress(target string) function to resolve hostnames to IPs and query ARP table via OS-specific commands; added isPrivateIP() helper to detect private/local IPs for triggering MAC lookups
Output infrastructure
pkg/runner/output.go
Added MacAddress field to Result and jsonResult structs; introduced WriteJSONOutputWithMac() and WriteCsvOutputWithMac() functions; updated existing WriteJSONOutput() and WriteCsvOutput() to delegate to new *WithMac variants with empty MAC addresses
Integration and propagation
pkg/runner/runner.go
Updated result generation to populate MacAddress from hostResult.MacAddress; replaced WriteJSONOutput() and WriteCsvOutput() calls with WriteJSONOutputWithMac() and WriteCsvOutputWithMac() variants across multiple output branches; integrated MAC address propagation into per-host and per-host-port output paths

Sequence Diagram(s)

sequenceDiagram
    participant Runner as runner.go
    participant Results as results.go
    participant ARP as ARP Table
    participant Output as output.go
    
    Runner->>Results: GetIPsPorts(target)
    Results->>Results: Resolve IP
    alt Private IP detected
        Results->>Results: isPrivateIP(ip)
        Results->>Results: GetMacAddress(target)
        Results->>ARP: Query ARP table (OS command)
        ARP-->>Results: MAC address
        Results->>Results: Set hostResult.MacAddress
    end
    Results-->>Runner: Return HostResult with MacAddress
    
    Runner->>Output: WriteJSONOutputWithMac(..., macAddress, ...)
    Output->>Output: Populate Result.MacAddress
    Output-->>Runner: JSON output written
    
    Runner->>Output: WriteCsvOutputWithMac(..., macAddress, ...)
    Output->>Output: Populate Result.MacAddress
    Output-->>Runner: CSV output written
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • ARP integration complexity: The GetMacAddress() function uses OS-specific shell commands to query ARP tables; verify cross-platform compatibility (Linux/macOS/Windows) and error handling for edge cases.
  • Private IP detection logic: Ensure the isPrivateIP() helper correctly identifies all RFC1918 ranges and link-local addresses.
  • Output path refactoring: Multiple branches in runner.go now call *WithMac variants; confirm all call sites are updated consistently and backward compatibility is maintained via delegation.
  • MAC propagation through result chain: Trace the MacAddress field from HostResultResult → JSON/CSV output to ensure no data is lost or duplicated.

Poem

🐰 A hop through networks, both far and near,
MAC addresses found, crystal clear!
ARP tables whisper their secrets true,
Private IPs yield their hardware view,
Output streams flowing with addresses bright,
Discovery complete—the network's delight!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-mac-address

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ead04ec and 6bbf9ab.

📒 Files selected for processing (3)
  • pkg/result/results.go (4 hunks)
  • pkg/runner/output.go (5 hunks)
  • pkg/runner/runner.go (5 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mzack9999
Copy link
Copy Markdown
Member Author

@coderabbitai create an issue for this PR related to implementing MAC Address lookup for private ips

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 8, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get details about the PR to understand context
gh pr view 1580 --json title,body,url

Length of output: 108


🏁 Script executed:

#!/bin/bash
# Create the issue for implementing MAC Address lookup for private IPs
gh issue create \
  --title "Implement MAC Address lookup for private IPs" \
  --body "This issue tracks the implementation of MAC Address lookup functionality for private IP addresses.

**Context:**
This is a follow-up from PR #1580 which added initial MAC address support.

**Requested by:** @Mzack9999

**Related PR:** https://github.com/projectdiscovery/naabu/pull/1580" \
  --assignee Mzack9999

Length of output: 53


@Mzack9999: I've created issue #1581 for implementing MAC Address lookup for private IPs. The issue has been assigned to you and includes a reference to this PR.

You can view it here: #1581

@Mzack9999 Mzack9999 linked an issue Nov 8, 2025 that may be closed by this pull request
@Mzack9999 Mzack9999 marked this pull request as ready for review November 10, 2025 09:50
@auto-assign auto-assign bot requested a review from dogancanbakir November 10, 2025 09:50
@Mzack9999 Mzack9999 merged commit d711452 into dev Nov 10, 2025
12 of 13 checks passed
@Mzack9999 Mzack9999 deleted the feat-mac-address branch November 10, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement Most issues will probably ask for additions or changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement MAC Address lookup for private IPs

1 participant