Programming, tutorials, mechatronics, operating systems, and other tech stuff

TP-Link Access Point/router batch reboot/restarter php script

41 comments
Untuk versi bahasa indonesia, silahkan klik disini

If you have a large wireless network infrastructure, which consist of many Access point and Wi-Fi router. And at some cases, you need to safely reboot all access point. It could be very annoying if you have to login to each AP/Router and restart them individually one by one.

Why bother doing all those work manually when you could write a code to do it automatically?

Well, luckily in my cases, all of the access point have the same brand. it's TP-Link. After some research, i found a way to reboot those brand's access point and router by using URL. Then i wrote this PHP script to get the job done.

In my infrastructure, i made all access point and router have different IP sub from DHCP-ed network. All have same username and password, all have the same method of authentication (using http auth). This script written in PHP, running in terminal/console. So it's very handy when it comes to automation. Just add it to cron and voila. Don't forget to make it executable "chmod 777" if you want to run it under linux and make sure you have php5-cli installed.

Here i share the script i wrote, you can customize it to suit your infrastructure, be creative.


#!/usr/bin/php

<?php

//----------Auth config

$apUser="admin";

$apPass="admin";

//----------Lists of AP and it's IP address

$apList=Array(

Array("Ext1","192.168.0.15"),

Array("Ext2","192.168.0.17"),

Array("Jalak","192.168.0.2"),

Array("Barat","192.168.0.3"),

Array("-","192.168.0.5"),

Array("Parkit","192.168.0.6"),

Array("Murai","192.168.0.9"),

Array("Nuri","192.168.0.10"),

Array("Kenari","192.168.0.12"),

Array("Cucak","192.168.0.13"),

Array("Hud-Hud","192.168.0.14"),

);



function curl_download($ip){

$Url="http://".$ip."/userRpm/SysRebootRpm.htm?Reboot=Reboot";

// is cURL installed yet?

if (!function_exists('curl_init')){

die('Sorry cURL is not installed!');

}



// OK cool - then let's create a new cURL resource handle

$ch = curl_init();



// Set URL to download

curl_setopt($ch, CURLOPT_REFERER, "http://".$ip."/userRpm/SysRebootRpm.htm");

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux i686;rv:12.0) Gecko/20100101 Firefox/12.0");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_URL, $Url);

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($ch, CURLOPT_USERPWD, $apUser.":".$apPass);

curl_setopt($ch, CURLOPT_TIMEOUT, 120);



$output = curl_exec($ch);



curl_close($ch);



return $output;

}



print "\n";

print "\e[1;34mAP Resetter. By Cybermujahidz\e[0m\n";

print "\n";

print "List of AP:\n";

foreach($apList as $ap){

print str_pad($ap[1],15,' ',STR_PAD_RIGHT)." ".str_pad($ap[0],10,' ',STR_PAD_RIGHT)." queued\n";

}

print "\n";

print "Resetting ALL AP\n";

print "----------------\n";

foreach($apList as $ap){

if(curl_download($ap[1])){

print str_pad($ap[1],15,' ',STR_PAD_RIGHT)." ".str_pad($ap[0],10,' ',STR_PAD_RIGHT)." [ \e[1;32mAP Rebooted\e[0m ]\n";

}else{

print str_pad($ap[1],15,' ',STR_PAD_RIGHT)." ".str_pad($ap[0],10,' ',STR_PAD_RIGHT)." [ \e[1;31m AP Down \e[0m ]\n";

}

}

print "AP reset finished.\n";

print "------------------\n";

?>

41 comments :

  1. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing...
    Regards,
    PHP Training in Chennai

    ReplyDelete
  2. Great blog.. I found some useful info in your article, it was awesome to read, thanks for sharing this great content to my vision.. Software Testing Training Institute in Chennai | Selenium Training Institute in Chennai | ISTQB Training Institute in Chennai

    ReplyDelete
  3. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    java training in bangalore

    ReplyDelete
  4. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Web Designing Training Institute in Chennai | Web Designing Training Institute in Velachery

    ReplyDelete
  5. Best of luck for your next blog.
    Thank you for such a wonderful article and sharing.God bless you.!!!!
    Best CorelDraw Training Institute in Chennai | No.1 CorelDraw Training Institute in Velachery

    ReplyDelete
  6. Nice post.Great information on this blog, many useful and new ideas i'm learning here.It's very helpful.
    Best AWS Training Institute in Chennai | Best AWS Training Institute in Velachery

    ReplyDelete
  7. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    MCA Project Center in Chennai | MCA Project Center in Velachery

    ReplyDelete
  8. Thanks for sharing such a great blog post. I really like your blog post which is so informative.
    white label website builder

    mobile website builder

    ReplyDelete
  9. Very good and informative article. Thanks for sharing such nice article, keep on updating...
    Best AWS Training Institute in Chennai | Best AWS Training Institute in Velachery

    ReplyDelete
  10. Excellent Blog very imperative good content, this article is useful to beginners and real time Employees. Selenium Training in Chennai| Oracle Training in Chennai

    ReplyDelete
  11. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.. Big Data Training in Chennai Digital Marketing Training in Chennai

    ReplyDelete
  12. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. iOS Training in Chennai | iOS Training institutes in Chennai

    ReplyDelete
  13. Concepts are very clear. Thank you for sharing such a valuable content. we are very happy to receive such a nice one Thank you... Devops Training in Chennai | AWS Training in Chennai

    ReplyDelete
  14. I wish to show thanks to you just for bailing me out of this particular trouble. As a result of checking through the net and meeting techniques that were not productive, I thought my life was done... iOS Training in Chennai | Big Data Training in Chennai

    ReplyDelete
  15. Very nice article this would definitely help the beginners, coding made easy with the help of example you shared... Oracle Training in Chennai | Selenium Training in Chennai

    ReplyDelete
  16. If you are going for finest contents like me, simply pay a quick visit this web page every day since it presents feature contents, thanks.
    Excellent Summer Courses in Guindy | Best Summer Classes in Chennai

    ReplyDelete
  17. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...
    Dot-net Summer Course training Institute in Chennai|Dot-net Summer Course training Institute in Ashok Nagar

    ReplyDelete
  18. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Dotnet Training Institute in Chennai |Dotnet Training Institute in Velachery

    ReplyDelete
  19. Excellent information...It was getting more information about your blog. Thanks for sharing, keep updating.
    AWS Training Institute in Chennai|AWS Training Institute in Velachery

    ReplyDelete
  20. Very good and informative article. Thanks for sharing such nice article, keep on updating such good articles.
    Best cloud Computing Training Institute in Chennai | Best cloud Computing Training Institute in Velachery

    ReplyDelete
  21. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Best MCSE/MCSA Certificate Training Institute in Chennai|Best MCSE/MCSA Certificate Training Institute in Velachery

    ReplyDelete
  22. Thanks admin, your blog gives lots of information to me. Keep sharing more like this..DotNet Project Center in Chennai | DotNet Project Center in Velachery

    ReplyDelete
  23. Awesome..You have clearly explained.Its very useful for me to know about new things..Keep on blogging.
    InDesign Certification Center in Chennai | No.1 InDesign Training in Keelkattalai

    ReplyDelete
  24. Such a cute blog. Thank you for blogging. Keep adding more blogs. Very nicely presented.

    ReplyDelete
  25. Wonderul post to sharing..Thank you..DotNet Project Center in Chennai | <a href="https://www.alltechzsolutions.in/dotnet-project.phpDotNet Project Center in Velachery</a>

    ReplyDelete
  26. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    IBM BPM Online Training in Chennai
    IBM BPM Online Training

    ReplyDelete
  27. Thanks for your informative article. Your post helped me to understand the future and career prospects. Keep on updating your blog with such awesome article.
    Python Certification Center in Chennai | No.1 Python Exams in Nanganallur

    ReplyDelete
  28. Great blog.. I found some useful info in your article, it was awesome to read, thanks...
    BE Final Year Project Center in Chennai | BE Project in Madipakkam

    ReplyDelete
  29. Great survey, I'm sure you're getting a great response. https://192-168-i-i.com

    ReplyDelete