Commit 75035b44 authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Fix netstat parsing.

BUG=512188

Review URL: https://codereview.chromium.org/1238293004

Cr-Commit-Position: refs/heads/master@{#339691}
parent b16c3122
...@@ -109,8 +109,9 @@ def IsDevicePortUsed(device, device_port, state=''): ...@@ -109,8 +109,9 @@ def IsDevicePortUsed(device, device_port, state=''):
Returns: Returns:
True if the port on device is already used, otherwise returns False. True if the port on device is already used, otherwise returns False.
""" """
base_url = '127.0.0.1:%d' % device_port base_urls = ('127.0.0.1:%d' % device_port, 'localhost:%d' % device_port)
netstat_results = device.RunShellCommand('netstat') netstat_results = device.RunShellCommand(
['netstat', '-a'], check_return=True, large_output=True)
for single_connect in netstat_results: for single_connect in netstat_results:
# Column 3 is the local address which we want to check with. # Column 3 is the local address which we want to check with.
connect_results = single_connect.split() connect_results = single_connect.split()
...@@ -120,7 +121,7 @@ def IsDevicePortUsed(device, device_port, state=''): ...@@ -120,7 +121,7 @@ def IsDevicePortUsed(device, device_port, state=''):
raise Exception('Unexpected format while parsing netstat line: ' + raise Exception('Unexpected format while parsing netstat line: ' +
single_connect) single_connect)
is_state_match = connect_results[5] == state if state else True is_state_match = connect_results[5] == state if state else True
if connect_results[3] == base_url and is_state_match: if connect_results[3] in base_urls and is_state_match:
return True return True
return False return False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment