Skip to content

Instantly share code, notes, and snippets.

@elvis-epx
Created August 7, 2026 17:37
Show Gist options
  • Select an option

  • Save elvis-epx/afd44a102221c171a8e70cb0cee97df6 to your computer and use it in GitHub Desktop.

Select an option

Save elvis-epx/afd44a102221c171a8e70cb0cee97df6 to your computer and use it in GitHub Desktop.
Reseta roteador Elsys Amplimax 4G programaticamente
// module.paths.push('/usr/lib/node_modules');
const puppeteer = require('puppeteer');
let Timeout = require('await-timeout');
let url_base = process.argv[2];
let username = process.argv[3];
let password = process.argv[4];
(async () => {
let get_internet_status = async (page) => {
console.log("### testing icon_conexao");
const src = await page.$eval('#icon_conexao', img => img.src);
if (src.includes('WEB-SIM')) {
console.log("conectado regularmente");
return;
}
console.log("### clicking status_sistema");
const btn = await page.$("#menu_status");
await btn.click();
await Timeout.set(5000);
console.log("### equivalent to clicking button Sistema");
await page.evaluate(() => {
// in page context
mostra('sistema', null);
});
await Timeout.set(5000);
console.log("### waiting for estilo_input");
await page.waitForSelector('#estilo_input', { timeout: 7000 });
console.log("### equivalent to clicking button estilo_input");
await page.goto(url_base + "/countDownPage.htm", {waitUntil: 'networkidle2'});
await Timeout.set(5000);
console.log("reset solicitado");
};
let login = async (page) => {
console.log("### fazendo login");
process.stderr.write("### username\n");
await page.locator('#username').fill(username);
process.stderr.write("### password\n");
await page.locator('#password').fill(password);
process.stderr.write("### submit\n");
await page.click('button[type="submit"]');
process.stderr.write("### aguardando por icon_conexao\n");
await page.waitForSelector('#icon_conexao', { timeout: 7000 });
await get_internet_status(page);
}
const browser = await puppeteer.launch({headless: "new"});
const page = await browser.newPage();
page.on('console', (msg) => {
msg = msg.text();
process.stderr.write("(console)" + msg + "\n");
});
page.on('pageerror', (err) => {
process.stderr.write("(page error)" + err.toString() + "\n");
});
process.stderr.write("### carregando\n");
await page.goto(url_base + "/", {waitUntil: 'networkidle2'});
console.log("### aguardando por elemento password ou icon_conexao");
await Promise.any([
page.waitForSelector('#password', { timeout: 5000 }),
page.waitForSelector('#icon_conexao', { timeout: 5000 }),
]);
var is_login = !! await page.$('#password');
var is_main = !! await page.$('#icon_conexao');
if (is_main) {
await get_internet_status(page);
} else if (is_login) {
await login(page);
}
await browser.close();
process.exit(0);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment