Developer Community

Reply
Highlighted
Occasional Contributor I

SSID pw change

Hi,

i'm trying to change a SSID WPA2 Key by a python Script.

What i got til now:

- login to our Mobility Master.

- figure out the Cookie ID -> not the best way but it works ^^

- Logout (see attachment)

 

Now i tried out to post a new password with a curl command at the api gui.

->that works, but only if i safe the "Pending Changes" at the main gui.

 

So you guys know how to post a curl command like this in pyhton? (attachment)

 

It it also necessary to safe changes (After the post command) by script?

 

Thanks

Dany

 

 

 

MVP

Re: SSID pw change

Hey man,

 

Here is how to access your cookie in a more sane way:

 

l = json.loads(login.content)
cookie = l['_global_result']['UIDARUBA']
Aranya AB, Sweden
ACMP, ACCA, CWNA, CWDP
Aruba Employee

Re: SSID pw change

I think you'll need to save as well, essentially commiting the 'Pending Changes', you can do that with a write mem:

 

wm_call = session.post(
"{}configuration/object/write_memory?config_path=%2Fmd&UIDARUBA={}".format(url, cookie)
Occasional Contributor I

Re: SSID pw change

Hey,

 

thanks for the feedback :)

 

So i modifyed the script and deployed it without an error (except for the https InsecureRequestWarning )

 

But my SSID "Test_PW" didn't change the WPA2 Key....is my playload right? Or is there a better way to change a WPA2 Key by script?

 

 

MVP

Re: SSID pw change

For each post you make against the API you should get a reply back.

Paste the content here, maybe it reveals some clues.

Aranya AB, Sweden
ACMP, ACCA, CWNA, CWDP
Occasional Contributor I

Re: SSID pw change

 

 

for the wm_call post i get:

b'{\n  "write_memory": {\n    "_result": {\n      "status": 0, \n      "status_str": "Success"\n    }\n  }, \n  "_global_result": {\n    "status": 0, \n    "status_str": "Success", \n    "_pending": false\n  }\n}'

 

for the create_PW i get this error:

b'{\n  "Error": "Exception raised while processing request"\n}'

 

for both i get the status code "200"

 

maybe a fundamental error?

 

 

 

MVP

Re: SSID pw change

Hey, 

Try this (written for python 2.7)

 

import requests
import json

#EDIT THESE VARIABLES
#IP, username and PW for MM authentication
ip = 'ip'
username = 'username'
password = 'password'

#current ssid_profile name you want to edit
ssid_prof_name = 'ssid_profile_name'

#new password for SSID
new_psk = 'new_psk_here'

#%2F replaces slash (below converts to /md/FOLDER1) config_path = '%2Fmd%2FFOLDER1' #END baseURL = 'https://{}:4343/v1'.format(ip) auth = {'username': username, 'password': password} s = requests.Session() login = s.post('{}/api/login'.format(baseURL), data=auth, verify=False) loginData = json.loads(login.content) cookie = loginData['_global_result']['UIDARUBA'] payload = { "ssid_prof": [ { "profile-name": ssid_prof_name, "_action": "add", "wpa_passphrase": { "wpa-passphrase": new_psk, "_action": "add" } } ] } data_set = s.post('{}/configuration/object?config_path={}&UIDARUBA={}'.format(baseURL, config_path, cookie), json=payload, verify=False) print data_set.content

Note that there is no logout or commit posts in above code, but you've figured that out already :)

Aranya AB, Sweden
ACMP, ACCA, CWNA, CWDP
Aruba Employee

Re: SSID pw change

In dataset this:

 

data=json.dumps(payload)

 

Can just be:

 

json=payload

MVP

Re: SSID pw change

Oh yeah, didnt think of that. Edited :)

Aranya AB, Sweden
ACMP, ACCA, CWNA, CWDP
Occasional Contributor I

Re: SSID pw change

Hey,

 

thanks for your support!

So i added the script from dojjan.

 

The script is doning well and i get no errors :)

But i figured out two problems:

1.

the changes will not be saved. If i take a look at the MM Webinterface, it offers me the "pending changes" button . But if i execute the script, go to the api webinterface and  do the post command:

https://IP_MM:4343/v1/configuration/object/write_memory?config_path=%2Fmd%2FTB&UIDARUBA=5e4b0198-cff4-476d-aadf-a427c24e2511

the changes will be saved.

Are the any bugs in my postcommad? Or is it necessary to do the "wr_mem" in a separate script?

 

2. How do i kick out connected users of the SSID? The SSID is only for guests and should change daily.

 

I hope you can help me a nother time ;)

 

Thanks

 

 

 
import requests
import json

#EDIT THESE VARIABLES
#IP, username and PW for MM authentication
ip = 'ip'
username = 'username'
password = 'password'

#current ssid_profile name you want to edit
ssid_prof_name = 'Test_PW'

#new password for SSID
new_psk = '123456789'

#%2F replaces slash (below converts to /md/TB)
config_path = '%2Fmd%2FTB'
#END

baseURL = 'https://{}:4343/v1'.format(ip)

auth = {'username': username, 'password': password}

s = requests.Session()
login = s.post('{}/api/login'.format(baseURL), data=auth, verify=False)
loginData = json.loads(login.content)

cookie = loginData['_global_result']['UIDARUBA']



payload = {
    "ssid_prof": [
        {
        "profile-name": ssid_prof_name,
        "_action": "add",
        "wpa_passphrase": {
            "wpa-passphrase": new_psk,
            "_action": "add"
        }
        }
    ]
    }


data_set = s.post('{}/configuration/object?config_path={}&UIDARUBA={}'.format(baseURL, config_path, cookie), json=payload, verify=False)

print(data_set.content)



wm_call = s.post("{}configuration/object/write_memory?config_path={}&UIDARUBA={}".format(baseURL, config_path, cookie))

print(wm_call.content)


logout =  s.post('{}/api/logout'.format(baseURL), data=auth, verify=False)
print("Logout Status: ", logout.status_code)
print("############################")
print("############################")

 

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: