Skip to content

Add IP enrichment with PTR, ASN, and country flag#8

Merged
linyows merged 9 commits into
mainfrom
add-ip-enrichment
Apr 13, 2026
Merged

Add IP enrichment with PTR, ASN, and country flag#8
linyows merged 9 commits into
mainfrom
add-ip-enrichment

Conversation

@linyows

@linyows linyows commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add IP enrichment to show command: reverse DNS (PTR), ASN number/organization, and country code for each source IP
  • Uses Team Cymru's DNS-based WHOIS service — no external API dependencies
  • IPv4/IPv6 support with private IP detection and result caching
  • Merge HEADER FROM / ENVELOPE FROM into single FROM column (header/envelope only when they differ)
  • Dynamic column widths computed from actual data content
  • Country displayed as flag emoji (e.g. US → 🇺🇸)
  • C ABI reports_enrich_ip() for SwiftUI integration
  • Enrichment enabled by default, disable with --no-enrich

New files

  • src/ipinfo.zig — IP enrichment module (PTR lookup, Team Cymru DNS TXT queries, response parsing)

Example output

SOURCE IP     PTR                     ASN                                        CC COUNT DISP FROM         DKIM SPF
------------- ----------------------- ------------------------------------------ -- ----- ---- ------------ ---- ----
209.85.220.69 mail-sor-f69.google.com AS15169 GOOGLE - Google LLC, US            🇺🇸 2     none shiokaze.net fail fail
163.44.185.53 ent001.phy.lolipop.jp   AS7506 INTERQ GMO Internet Group, Inc., JP 🇯🇵 6     none shiokaze.net fail pass

Test plan

  • Unit tests for IP enrichment (private IP detection, IPv4/IPv6 query building, Cymru response parsing, DNS packet construction)
  • Unit tests for country flag emoji conversion
  • Unit tests for FROM column merging
  • zig build test passes
  • Manual verification with reports show <id> on real DMARC/TLS-RPT reports

🤖 Generated with Claude Code

linyows and others added 9 commits April 13, 2026 15:44
Add --enrich flag to `show` command that displays reverse DNS (PTR),
ASN number/organization, and country code for each source IP using
Team Cymru's DNS-based WHOIS service. Includes IPv4/IPv6 support,
private IP detection, result caching, and C ABI for SwiftUI integration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show PTR/ASN/country info by default instead of requiring --enrich.
Users can disable it with --no-enrich if needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Compute column widths from actual data before rendering so ASN and
  other long fields are not truncated unnecessarily
- Merge HEADER FROM / ENVELOPE FROM into a single FROM column,
  showing "header/envelope" only when they differ
- Display country code as flag emoji (e.g. US → 🇺🇸) using
  Unicode Regional Indicator Symbols

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use separate buffers for each Regional Indicator Symbol encoding
to avoid slice arithmetic overflow on the shared buffer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Emoji columns use display width (2 chars) for padding instead of
byte count (8 bytes). Use plain text "CC" header instead of emoji
to avoid inconsistent header width across terminals.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add reports_enrich_ip C ABI wrapper with in-memory cache
- Add IpEnrichment model with PTR, ASN, and country flag helpers
- Replace ENVELOPE FROM/HEADER FROM columns with merged FROM column
- Add PTR, ASN, CC (flag emoji) columns to DMARC records table
- Add PTR, ASN columns to TLS-RPT failure details table
- Clear enrichment cache on report switch to avoid stale data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reuse writeTableRow/writeSepRow for consistent table rendering.
Column widths are computed from data content + 1 char padding.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linyows linyows merged commit 0f4d1e8 into main Apr 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant