ProfessionallyEvil / nmap_oui_update

A script to download OUI data from the IEEE and parse it into the nmap-mac-prefixes file so Nmap has the latest OUI data.
MIT License
9 stars 2 forks source link

Unicode in print_info throws codec error #1

Open SpareSimian opened 3 months ago

SpareSimian commented 3 months ago
 [*] Creating backup directory: /tmp/nmap_oui_update/backups
 [*] Creating backup of nmap-mac-prefixes: nmap-mac-prefixes.20240621.072930
 [*] Downloading latest copy of OUI data from IEEE...
 [+] Downloaded to /tmp/nmap_oui_update/ieee_oui_data.txt (5800716 bytes)
 [*] Processing data: 7C3180 => SMK corporationTraceback (most recent call last):
  File "nmap_oui_update.py", line 189, in <module>
    sys.exit(main())
  File "nmap_oui_update.py", line 179, in main
    if parse_oui_file(backup_copy):
  File "nmap_oui_update.py", line 137, in parse_oui_file
    endline="\r")
  File "nmap_oui_update.py", line 54, in print_info
    sys.stdout.write(f" [{BLU}*{NC}] {msg}{endline}")
UnicodeEncodeError: 'ascii' codec can't encode character '\xa0' in position 70: ordinal not in range(128)

(I've edited out all the preceding "Processing Data" lines. With a bit of editing and using an online Unicode detector, I think the record with Unicode is just after OUI 905607.)

I haven't used Python and Unicode enough that the solution jumps out at me. This has some hints on what's going wrong:

https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20

Unicode detector for pasting text from the raw file: https://freetools.textmagic.com/unicode-detector

SpareSimian commented 3 months ago

I forgot to mention that I'm using Python 3.6 under CentOS 7.

SpareSimian commented 3 months ago

Simple fix is to sanitize org:

org = org.encode('utf-8')