def set_wifi_interface_to_wpa_wpa2(ifname, if_ip, config_file):
    while True:
        cmd = "sudo ifconfig " + ifname + " down"
        cmd_result = cmd_exec(cmd)
        if cmd_result is False:
            result = False
            break
        #if (subprocess.call(cmd, shell=True) is False):
          #  result = False
           # break
        cmd = "sudo ifconfig " + ifname + " up"
        cmd_result = cmd_exec(cmd)
        if cmd_result is False:
            result = False
            break
        #if (subprocess.call(cmd, shell=True) is False):
          #  result = False
           # break
        cmd = "sudo iwconfig " + ifname + " mode managed"
        cmd_result = cmd_exec(cmd)
        if cmd_result is False:
            result = False
            break
        #if (subprocess.call(cmd, shell=True) is False):
          #  result = False
           # break

        cmd = "sudo rm /var/run/wpa_supplicant/wlan1"
        cmd_result = cmd_exec(cmd)
        #if cmd_result is False:
          #  print "Error al ejecutar remove, no existe el archivo"
            #result = False
            #break
        #if (subprocess.call(cmd, shell=True)) is False:
        	#print "error al ejecutar rm"
		
        cmd = "sudo killall wpa_supplicant"
        cmd_result = cmd_exec(cmd)
        #if (subprocess.call(cmd, shell=True)) is False:
          #  print "Error al ejecutar killall, no existe el archivo"

        cmd = "sudo wpa_supplicant -B -Dnl80211,wext -i " + ifname + " -c " + config_file
        if (subprocess.call(cmd, shell=True) is False):
            print "Unable to run wpa_supplicant"
            result = False
            break

        cmd = "sudo ifconfig " + ifname + " " + if_ip
        if (subprocess.call(cmd, shell=True) is False):
            print "Unable to configure wlan0 with IP address"
            result = False
            break

        result = True
        break # Get out anyway
    #------WhileLoop ends here-------
    return result
Example #2
0
def set_wifi_interface_to_wpa_wpa2(ifname, if_ip, config_file):
    #while True:
    cmd = "sudo ifconfig " + ifname + " down"
    retVal = cmd_exec(cmd)
    #print retVal
    if retVal[0] is False:
        msg = "Error al ejecutar ifconfig down"
        msg = retVal[1]
        result = False
        return (result, msg)
    
    cmd = "sudo ifconfig " + ifname + " up"
    retVal = cmd_exec(cmd)
    if retVal[0] is False:
        msg = "Error al ejecutar ifconfig up"
        msg = retVal[1]
        result = False
        return (result, msg)
  
    cmd = "sudo iwconfig " + ifname + " mode managed"
    retVal = cmd_exec(cmd)
    if retVal[0] is False:
        msg = "Error al ejecutar iwfconfig mode managed"
        msg = retVal[1]
        result = False
        return (result, msg)

    cmd = "sudo rm /var/run/wpa_supplicant/wlan0"
    subprocess.call(cmd, shell=True)

    cmd = "sudo killall wpa_supplicant"
    subprocess.call(cmd, shell=True)

    cmd = "sudo wpa_supplicant -B -Dnl80211,wext -i " + ifname + " -c " + config_file
    retVal = cmd_exec(cmd)
    if retVal[0] is False:
        msg = "Unable to run wpa_supplicant"
        msg = retVal[1]
        result = False
        return (result, msg)
    
    cmd = "sudo ifconfig " + ifname + " " + if_ip
    retVal = cmd_exec(cmd)
    if retVal[0] is False:
        msg = "Unable to configure wlan0 with IP address"
        msg = retVal[1]
        result = False
        return (result, msg)
    
    result = True
    msg = ''
    return (result, msg)