1

We are making a system management website where we need to have the option to change the wifi channel and restart or shut down the router. We made the Ajax functions that can do this if the router doesn't have a password. The functions simlpy sending the url with the necessary parameters to the router, for example: http://1.1.1.1/WifiRadioSet?adv_mode=bgn&adv_channel=11. But obviously you don't want to leave the router without password.

So my question is it possible to somehow login to a router automatically with PHP and/or Ajax or not?

1
  • Depends on the router and how it authenticates/authorizes requests. Commented Feb 8, 2018 at 14:40

1 Answer 1

1

Most routers use basic authentication. Therefore, you should be able to login via ajax using basic auth.

This article has a good example of how to do basic auth with ajax - https://zinoui.com/blog/ajax-basic-authentication

Or a good example I found here:

$.ajax({
     type: "GET",
     url: "http://localhost:8080/test",
     data: {username: "ajax", password: "code"},
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: OnSuccessCall,
     error: OnErrorCall
 });
Sign up to request clarification or add additional context in comments.

3 Comments

And only if the router allows CORS, + most routers are not on http://localhost :/
Good point. You could proxy this request through a backend though. For example if you have a php backend, send the ajax request to the php server and have the php execute a network request to the router with the basic auth credentials.
Thank you guys. Actually it works with Ajax, but I decided to do it with php cURL at least that way the password isn't directly exposed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.