nitefood / asn

ASN / RPKI validity / BGP stats / IPv4v6 / Prefix / URL / ASPath / Organization / IP reputation / IP geolocation / IP fingerprinting / Network recon / lookup API server / Web traceroute server
MIT License
1.31k stars 159 forks source link

Issue with obtaining v4 and v6 prefixes on MACOS #45

Closed Therros2023 closed 1 year ago

Therros2023 commented 1 year ago

Hi nitefood,

Mac seems to have an issue grabbing prefixes both IPv4 and v6:

:~/repo/asn [master]% sw_vers
ProductName:        macOS
ProductVersion:     13.2.1
BuildVersion:       22D68
~/repo/asn [master]% git --no-pager log --oneline --no-decorate -1
f53ff33 IPv6 improvements (fixes #43) - improved host IPv6 detection reliability using ifconfig.co - improved host AS detection using RIPEStat for IPv6 and dual stack hosts - [server mode] switched default binding address to ::1 instead of 127.0.0.1 for IPv6 and dual stack hosts
~/repo/asn [master]% ./asn 5505

╭─────────────────────╮
│ ASN lookup for 5505 │
╰─────────────────────╯

 AS Number     ──> 5505
 AS Name       ──> VADAVO, ES
 Organization  ──>  (VDV-VLC-RED06 VDV-VLC-RED06 - CLIENTES TELECOM)
 Abuse contact ──> abuse@vadavo.com
 AS Reg. date  ──> 2016-12-13 08:28:07
 Peering @IXPs ──> DE-CIX Madrid: DE-CIX Madrid Peering LAN • ESPANIX Madrid Lower LAN

╭──────────────────────────────────────────╮
│ BGP informations for AS5505 (VADAVO, ES) │
╰──────────────────────────────────────────╯

Retrieving prefix allocations and announcements for AS5505 (VADAVO, ES) (press CTRL-C to cancel)...zsh: killed     ./asn 5505

Seems to be an issue with how the connection to ripe is made, maybe?

~/repo/asn [master]% exec 85<>/dev/tcp/whois.ripe.net/43
zsh: no such file or directory: /dev/tcp/whois.ripe.net/43

~/repo/asn [master]% exec 3<>/dev/tcp/whois.ripe.net/43
zsh: no such file or directory: /dev/tcp/whois.ripe.net/43
nitefood commented 1 year ago

hey @Therros2023,

this appears to be a problem similar to #40. Please see if those steps help you.

Therros2023 commented 1 year ago

Hi @nitefood

Cheers - just did having a look. Updated brew

Update brew on the Mac: Exec command works in bash but not .zsh

bash-5.2$ exec 85<>/dev/tcp/whois.ripe.net/43

╭─────────────────────╮
│ ASN lookup for 5505 │
╰─────────────────────╯

 AS Number     ──> 5505
 AS Name       ──> VADAVO, ES
 Organization  ──> VADAVO SOLUCIONES SL (VDV-VLC-RED06 VDV-VLC-RED06 - CLIENTES TELECOM)
 Abuse contact ──> abuse@vadavo.com
 AS Reg. date  ──> 2016-12-13 08:28:07
 Peering @IXPs ──> DE-CIX Madrid: DE-CIX Madrid Peering LAN • ESPANIX Madrid Lower LAN

╭──────────────────────────────────────────╮
│ BGP informations for AS5505 (VADAVO, ES) │
╰──────────────────────────────────────────╯

Retrieving prefix allocations and announcements for AS550... (press CTRL-C to caRetrieving information for IPv6 prefix 1/1 (press CTRL-C to cancel)...Killed: 9

Still cannot do prefix retrival.

nitefood commented 1 year ago

Update brew on the Mac: Exec command works in bash but not .zsh

Ok, that's to be expected since that's BASH specific (the asn script itself is a BASH script, not a ZSH one)

Retrieving prefix allocations and announcements for AS550... (press CTRL-C to caRetrieving information for IPv6 prefix 1/1 (press CTRL-C to cancel)...Killed: 9



Still cannot do prefix retrival.

Can you try running the command as bash -x asn -v 5505 &> execution.log, and afterwards attach execution.log here in order to have more insight as to what's failing?

Therros2023 commented 1 year ago

Done.

See Attached. execution.log

nitefood commented 1 year ago

So it's indeed breaking in the exact spot where the script accesses the /dev/tcp pseudodevice (i.e. the persistent whois connection).

At this point I'm inclined to think Homebrew's BASH package has an issue with this. The possible options that I can see are two:

  1. reinstall the BASH package, making sure nothing taints its configuration, or
  2. install BASH using a different method, for instance with MacPorts, in the hope that the resulting shell is somehow less error prone than the one Homebrew installs.
Therros2023 commented 1 year ago

Reinstall of homebrew bash was unsuccessful. Will try macports next.

nitefood commented 1 year ago

Was looking around to see if there were traces of this error somewhere else, and this comment caught my eye. Not sure if this is really the case (furthermore they discuss ksh and not BASH), but the behavior looks consistent to what you're experiencing (and the explanation would be meaningful for BASH as well, since it suggests FD3 is "special" on MacOS). Closing FD 3 on MacOS apparently could trigger a SIGKILL, which is what you're experiencing in the end.

It's worth to test this idea by changing the code to use a FD other than 3. Please try the attached version that uses FD 6, and let me know. asn_fd6.txt

Therros2023 commented 1 year ago

Retrieving prefix allocations and announcements for AS550... (press CTRL-C to caRetrieving information for IPv6 prefix 1/1 (press CTRL-C to cancel)...Killed: 9

Therros2023 commented 1 year ago

Genius, that worked prefix retrieval is working again:

Good find with that post.

% asn 5505

╭─────────────────────╮
│ ASN lookup for 5505 │
╰─────────────────────╯

 AS Number     ──> 5505
 AS Name       ──> VADAVO, ES
 Organization  ──> VADAVO SOLUCIONES SL (VDV-VLC-RED06 VDV-VLC-RED06 - CLIENTES TELECOM)
 Abuse contact ──> abuse@vadavo.com
 AS Reg. date  ──> 2016-12-13 08:28:07
 Peering @IXPs ──> DE-CIX Madrid: DE-CIX Madrid Peering LAN • ESPANIX Madrid Lower LAN

╭──────────────────────────────────────────╮
│ BGP informations for AS5505 (VADAVO, ES) │
╰──────────────────────────────────────────╯

Retrieving prefix allocations and announcements for AS550... (press CTRL-C to ca IPv4 Prefixes  ────> 8
 IPv6 Prefixes  ────> 1
 BGP Neighbours ────> 39

╭──────────────────────────────────────────────╮
│ Peering informations for AS5505 (VADAVO, ES) │
╰──────────────────────────────────────────────╯

──────────────── Upstream Peers ────────────────

 TWELVE99 (1299)   HURRICANE (6939)   COGENT-174 (174)   MEER-AS (34549)
 CORE-BACKBONE (33891)   IP-MAX (25091)   FIBERTELECOM-AS (41327)   NEO-ASN (8218)
and more: 34927 3303 1239 35280 4455 60501 24482 13030 48348 9498 6057 8560

─────────────── Downstream Peers ───────────────

 SAFORWIFI (207495)   SVINT-ASN (200509)   LUXUNIT (48952)   SCS-AS (208248)
 IUKANET (205086)   S4N-AS (202054)

─────────────── Uncertain  Peers ───────────────

 EDGOO (47787)   NETACTUATE (36236)   STACLAR-CARRIER (34854)   VORBOSS_AS (25160)
 ONECOM-AS (51185)   NL-MLAB (41047)   Virtual-Technologies-Solutions-SA (37721)   DELTA-TELECOM-AS (29049)
and more: 264479 212483 14840 39384 29680

╭─────────────────────────────────────────────────╮
│ Aggregated IP resources for AS5505 (VADAVO, ES) │
╰─────────────────────────────────────────────────╯

───── IPv4 ─────

185.123.204.0/22
185.210.225.0/24
185.210.226.0/24
185.210.227.0/24
188.130.247.0/24
188.130.254.0/24

───── IPv6 ─────

2a03:9320::/32
nitefood commented 1 year ago

Awesome, will commit this fix later today and close the issue. Thanks for reporting!

Therros2023 commented 1 year ago

Nah, thanks for taking the time - much appreciated.