Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Suggestions for a script to test port and execute HTTP calls

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
pdario
Posts: 108
Joined: 2013-04-23 09:17

Suggestions for a script to test port and execute HTTP calls

#1 Post by pdario »

Hello!

In my environment, my wan router has a little bug: sometimes it loses a port mapping configuration (a WAN port is mapped to a port on server on the LAN).

I would like a script that:
  • tests if the wan port is reachable (open)
  • if not, launches some HTTP calls to reset the port mapping on the router web interface
For the second step, I need something that posts login/password and takes the cookie to make the following calls.

My questions are:
  • what language/tool do you suggest?
  • what's the best approach to grab the HTTP calls I make with my browser and replicate them on the Debian server?
Thank you a lot!!

User avatar
ruwolf
Posts: 643
Joined: 2008-02-18 05:04
Location: Banovce nad Bebravou
Has thanked: 41 times
Been thanked: 30 times

Re: Suggestions for a script to test port and execute HTTP calls

#2 Post by ruwolf »

I am afraid that I may not understand you exactly:
Do you want to replicate your browser behaviour during connecting to web interface of router on server?
I.e. do you want to make your debian server (automatically after detection of lossing of mapping) the same settings on web interface of router like you make by browser by hand?

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1418
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 80 times
Been thanked: 191 times

Re: Suggestions for a script to test port and execute HTTP calls

#3 Post by steve_v »

Testing ports should be fairly trivial (though probably requires a call to an external service to verify), but the best way of manipulating the webui will vary wildly depending on which variety of router you have and how it's web interface (particularly authentication and potential reliance on javascript) works.
Your best place to begin is probably your browsers debug/trace console and a general web search for "router reboot script" or the like, which yields many examples you might use as a staring point, done with everything from bash and curl to php to python and selenium/webdriver.

For full headless-browser based automation, in the past I might have suggested phantomjs... but that project appears dead, and I suspect everyone is using selenium these days. I gather there are even firefox extensions to record interactions for later playback.
If you're remotely handy with go, there's also surf, which would be a rather lighter solution while still behaving much like a real browser.

OTOH, if your router supports management over SSH or telnet I'd be inclined to take that as the much easier option.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

User avatar
ruwolf
Posts: 643
Joined: 2008-02-18 05:04
Location: Banovce nad Bebravou
Has thanked: 41 times
Been thanked: 30 times

Re: Suggestions for a script to test port and execute HTTP calls

#4 Post by ruwolf »

In most cases, console is not needed. Browsers like Chromium or FireFox have included Network Monitor in their Web Developer Tools (which are part of browser, no add-on or extension is required).

pdario
Posts: 108
Joined: 2013-04-23 09:17

Re: Suggestions for a script to test port and execute HTTP calls

#5 Post by pdario »

Wrapping up replies to last messages:
  • @ruwolf Yes, it seem I need to replicate full browser navigation with JS executing: I compared two different login calls and I saw the login/pwd pair is encrypted in different strings
  • @steve_v No access with SSH, it is a Vodafone provided router. But I'll look for custom mad scripts as you suggested
  • @ruwolf Yes, those browsers have network monitor, but that's not enough to control them

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1418
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 80 times
Been thanked: 191 times

Re: Suggestions for a script to test port and execute HTTP calls

#6 Post by steve_v »

pdario wrote: 2023-10-14 21:02 it seem I need to replicate full browser navigation with JS executing
No access with SSH, it is a Vodafone provided router.
Which all reminds me why, many years ago, I swore off accepting an ISP supplied router ever again, and instead built my own (running GNU/Linux of course).

As for your mission, good luck. I doubt you'll find anything ready to go, but enough people have tried similar missions (though usually for the purpose of simply rebooting such POS hardware) that there should be a few examples, at least so far as something to look at for inspiration anyway.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

pdario
Posts: 108
Joined: 2013-04-23 09:17

Re: Suggestions for a script to test port and execute HTTP calls

#7 Post by pdario »

Thank you!

User avatar
ruwolf
Posts: 643
Joined: 2008-02-18 05:04
Location: Banovce nad Bebravou
Has thanked: 41 times
Been thanked: 30 times

Re: Suggestions for a script to test port and execute HTTP calls

#8 Post by ruwolf »

pdario wrote: 2023-10-14 21:02 @ruwolf Yes, those browsers have network monitor, but that's not enough to control them[/list]
Yes, it is not for controlling of browser, but for inspecting (when and what is sent and what is received). I.e. what you should emulate (e.g. by script).

Post Reply