Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions wifite/model/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ class Target:
"""
_ansi_re = re.compile(r'\033\[[0-9;]*m')

def _pad_colored(self, colored_str, width, align='left'):
"""Pad a colored string to a specific visible width."""
visible = self._ansi_re.sub('', colored_str)
diff = width - len(visible)
if diff <= 0:
return colored_str
if align == 'right':
return ' ' * diff + colored_str
elif align == 'center':
left_pad = diff // 2
right_pad = diff - left_pad
return ' ' * left_pad + colored_str + ' ' * right_pad
else:
return colored_str + ' ' * diff

def __init__(self, fields):
"""
Initializes & stores target info based on fields.
Expand Down Expand Up @@ -249,7 +264,7 @@ def to_str(self, show_bssid=False, show_manufacturer=False):
decloaked_char = Color.s('{P}*') if self.decloaked else ' '
essid += decloaked_char

bssid = Color.s('{D}%s{W} ' % self.bssid) if show_bssid else ''
bssid = Color.s('{D}%s{W}' % self.bssid) if show_bssid else ''
if show_manufacturer:
oui = ''.join(self.bssid.split(':')[:3])
self.manufacturer = Configuration.manufacturers.get(oui, "")
Expand All @@ -260,7 +275,7 @@ def to_str(self, show_bssid=False, show_manufacturer=False):
mfg_name = f'{mfg_name[:max_oui_len - 3]}...'
else:
mfg_name = mfg_name.ljust(max_oui_len)
manufacturer = Color.s('{W}%s ' % mfg_name)
manufacturer = Color.s('{W}%s' % mfg_name)
else:
manufacturer = ''

Expand Down Expand Up @@ -328,21 +343,44 @@ def to_str(self, show_bssid=False, show_manufacturer=False):
power = f'{pwr_bar} {Color.s("{%s}%s" % (pwr_color, str(pwr_dbm).rjust(2)))}'

if self.wps == WPSState.UNLOCKED:
wps = Color.s(' {G}yes')
wps = Color.s('{G}yes')
elif self.wps == WPSState.NONE:
wps = Color.s(' {D} - ')
wps = Color.s('{D}-')
elif self.wps == WPSState.LOCKED:
wps = Color.s(' {R}lck')
wps = Color.s('{R}lck')
elif self.wps == WPSState.UNKNOWN:
wps = Color.s(' {O} ? ')
wps = Color.s('{O}?')
else:
wps = ' - '
wps = '-'

clients = Color.s('{D} - ')
if len(self.clients) > 0:
clients = Color.s('{G} %s' % str(len(self.clients)))

result = f'{essid} {bssid}{manufacturer}{channel} {encryption_display_string} {power} {wps} {clients}'
clients = Color.s('{G}%s' % str(len(self.clients)))
else:
clients = Color.s('{D}-')

# Column widths must match scanner.py header
COL_ESSID = 26
COL_BSSID = 19
COL_MFG = 23
COL_CH = 4
COL_ENC = 9
COL_PWR = 7
COL_WPS = 5
COL_CLI = 7
SEP = ' '
Comment on lines +361 to +370

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column width constants are now duplicated across wifite/util/scanner.py, wifite/ui/classic.py, and Target.to_str(). This creates an ongoing risk of the alignment bug recurring if one location changes without updating the others. Consider centralizing these widths/separator into a shared constant (or a small helper) that both header builders and to_str() reference.

Copilot uses AI. Check for mistakes.

parts = [self._pad_colored(essid, COL_ESSID)]
if show_bssid:
parts.append(self._pad_colored(bssid, COL_BSSID))
if show_manufacturer:
parts.append(self._pad_colored(manufacturer, COL_MFG))
parts.append(self._pad_colored(channel, COL_CH, 'right'))
parts.append(self._pad_colored(encryption_display_string, COL_ENC))
parts.append(self._pad_colored(power, COL_PWR, 'right'))
parts.append(self._pad_colored(wps, COL_WPS, 'center'))
parts.append(self._pad_colored(clients, COL_CLI, 'right'))

result = SEP.join(parts)
Comment on lines +361 to +383

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new fixed-width column formatting in Target.to_str() is meant to prevent header/data drift, but there are no tests asserting the exact column widths/separators (after stripping ANSI) for common combinations (with/without BSSID/MFG, different WPS states, different client counts). Adding a regression test that strips ANSI and checks column start positions/widths would help prevent this alignment bug from returning.

Copilot uses AI. Check for mistakes.

result += Color.s('{W}')
return result
Expand Down
27 changes: 21 additions & 6 deletions wifite/ui/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,35 @@ def display_targets(self, targets, show_bssid=False, show_manufacturer=False):
Color.pl('{+} {C}Targets{W}')
Color.pl('')

# Print header
header = ' NUM'
# Print header (column widths must match target.to_str())
col_num = 5
col_essid = 26
col_bssid = 19
col_mfg = 23
col_ch = 4
col_enc = 9
col_pwr = 7
col_wps = 5
col_cli = 7

header = ' ' + 'NUM'.rjust(col_num)
header += ' ' + 'ESSID'.ljust(col_essid)
if show_bssid:
header += ' BSSID '
header += ' ' + 'BSSID'.ljust(col_bssid)
if show_manufacturer:
header += ' MANUFACTURER '
header += ' ESSID CH PWR ENC WPS CLIENT'
header += ' ' + 'MANUFACTURER'.ljust(col_mfg)
header += ' ' + 'CH'.rjust(col_ch)
header += ' ' + 'ENCR'.ljust(col_enc)
header += ' ' + 'PWR'.rjust(col_pwr)
header += ' ' + 'WPS'.center(col_wps)
header += ' ' + 'CLI'.rjust(col_cli)
Color.pl(header)
Color.pl(' ' + '-' * (len(header) - 2))

# Print targets
for idx, target in enumerate(targets, start=1):
target_str = target.to_str(show_bssid=show_bssid, show_manufacturer=show_manufacturer)
Color.pl(' {G}%3d{W} %s' % (idx, target_str))
Color.pl(' {G}%s{W} %s' % (str(idx).rjust(col_num), target_str))

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In display_targets(), the table header starts with two leading spaces (header = ' ' + ...), but each row starts with a single leading space (Color.pl(' {G}%s{W} %s' ...)). This shifts the NUM column one character left relative to the header and can reintroduce alignment issues. Make the left padding consistent between header/separator and rows (either add one leading space to the row format string or drop one from the header/separator).

Suggested change
Color.pl(' {G}%s{W} %s' % (str(idx).rjust(col_num), target_str))
Color.pl(' {G}%s{W} %s' % (str(idx).rjust(col_num), target_str))

Copilot uses AI. Check for mistakes.

Color.pl('')

Expand Down
Loading