import os import json routes = json.loads(os.popen("ip -j -4 route").read()) ip='' for r in routes: if r.get("dev") == "wlan0" and r.get("prefsrc"): ip = r['prefsrc'] continue if ip == "": print('초기설정') elif ip == "10.42.0.1": print('초기설정') else: stream = os.popen('sudo nmcli connection up HOTSPOT') output = stream.read() print(output)