-
Notifications
You must be signed in to change notification settings - Fork 277
Fix WPS and CLI column alignment in scan display #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
@@ -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, "") | ||
|
|
@@ -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 = '' | ||
|
|
||
|
|
@@ -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 = ' ' | ||
|
|
||
| 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
|
||
|
|
||
| result += Color.s('{W}') | ||
| return result | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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)) | ||||||
|
||||||
| 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)) |
There was a problem hiding this comment.
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, andTarget.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 andto_str()reference.