@@ -98,13 +98,17 @@ public async Task<List<WirelessNetworkInfo>> RetrieveWirelessNetworks(string[] a
98
98
/// </summary>
99
99
/// <param name="adapterName">Name of the adapter.</param>
100
100
/// <param name="networkSsid">The network ssid.</param>
101
- /// <param name="password">The password.</param>
101
+ /// <param name="password">The password (8 characters as minimum length) .</param>
102
102
/// <param name="countryCode">The 2-letter country code in uppercase. Default is US.</param>
103
103
/// <returns>True if successful. Otherwise, false.</returns>
104
104
public async Task < bool > SetupWirelessNetwork ( string adapterName , string networkSsid , string password = null , string countryCode = "US" )
105
105
{
106
106
// TODO: Get the country where the device is located to set 'country' param in payload var
107
107
var payload = $ "country={ countryCode } \n ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n update_config=1\n ";
108
+
109
+ if ( ! string . IsNullOrWhiteSpace ( password ) && password . Length < 8 )
110
+ throw new InvalidOperationException ( "The password must be at least 8 characters length." ) ;
111
+
108
112
payload += string . IsNullOrEmpty ( password )
109
113
? $ "network={{\n \t ssid=\" { networkSsid } \" \n \t key_mgmt=NONE\n \t }}\n "
110
114
: $ "network={{\n \t ssid=\" { networkSsid } \" \n \t psk=\" { password } \" \n \t }}\n ";
@@ -215,12 +219,25 @@ public async Task<List<NetworkAdapterInfo>> RetrieveAdapters()
215
219
return result . OrderBy ( x => x . Name ) . ToList ( ) ;
216
220
}
217
221
222
+ /// <summary>
223
+ /// Retrieves the current network adapter.
224
+ /// </summary>
225
+ /// <returns>The name of the current network adapter.</returns>
226
+ public static async Task < string > GetCurrentAdapterName ( )
227
+ {
228
+ var result = await ProcessRunner . GetProcessOutputAsync ( "route" ) . ConfigureAwait ( false ) ;
229
+ var defaultLine = result . Split ( new [ ] { '\n ' } , StringSplitOptions . RemoveEmptyEntries )
230
+ . FirstOrDefault ( l => l . StartsWith ( "default" , StringComparison . OrdinalIgnoreCase ) ) ;
231
+
232
+ return defaultLine ? . Trim ( ) . Substring ( defaultLine . LastIndexOf ( " " , StringComparison . OrdinalIgnoreCase ) + 1 ) ;
233
+ }
234
+
218
235
/// <summary>
219
236
/// Retrieves current wireless connected network name.
220
237
/// </summary>
221
238
/// <returns>The connected network name.</returns>
222
239
public Task < string > GetWirelessNetworkName ( ) => ProcessRunner . GetProcessOutputAsync ( "iwgetid" , "-r" ) ;
223
-
240
+
224
241
private static void GetIPv4 ( string indentedLine , NetworkAdapterInfo adapter )
225
242
{
226
243
var addressText = ParseOutputTagFromLine ( indentedLine , "inet addr:" ) ??
0 commit comments