Close

Start wpa_supplicant, then start dhclient

A project log for Silly software wishlist

Motivation to do some software projects by writing them down.

lion-mclionheadlion mclionhead 03/18/2021 at 06:510 Comments

There's no useful answer for this on the internet, so the lion kingdom finally wrote a python script to do the job.  The mane reason for doing it is when the systemd scripts don't work.

#!/usr/bin/python


# start up wpa_supplicant, wait for a connection, then start up dhclient


import os
import sys
import subprocess


p = subprocess.Popen(['wpa_supplicant', 
        '-iwlan0', 
        '-c/etc/wpa_supplicant/wpa_supplicant.conf'],
    stdout=subprocess.PIPE)


while True:
    line = p.stdout.readline()
    print 'Got: ', line
    if "CTRL-EVENT-CONNECTED" in line:
        # start DHCP
        subprocess.call(['dhclient', '-v', 'wlan0'])


Discussions