Sometimes it’s not the networking devices that need the automating. Sometimes, you have to automate the things to fit the network. In this case, I was given the task of manually logging in and updating a bunch of Epson receipt printers to use DHCP/auto IP config instead of the static/manual IP config they have configured today.
When you hit the web UI, you’re presented with a fairly generic login popup, asking for a username and password. In this case, I was able to use the default credentials combo for nearly all of the devices, which things easy. You can use a simple Invoke-WebRequest command to initiate your connection:
Invoke-WebRequest -Uri "https://<local_printer_ip>"
This will very likely fail for a few different reasons, the first being that it redirects to HTTPS but also has a default SSL certificate which PS does not like. To get around that you just need to add the -SkipCertificateCheck parameter to the end of the code line. From here, you will find that you get an HTTP 401 auth error which will require you to pass the creds on with the request. I handled this by issuing a Get-Credential request and storing that in a variable which is passed on during the call using the -Credential parameter.
Rather than break down the rest of the findings, I’ll just share what I came up with (update <local_printer_ip> to value of your printer):
#Enter credentials to be used for login later
$c = Get-Credential
#Build a new authenticated session using credentials from above
Invoke-WebRequest -Uri 'https://<local_printer_ip>' -SessionVariable temp_session -Method GET -Credential $c -SkipCertificateCheck
#Issue update to auto/DHCP IP config
Invoke-WebRequest -UseBasicParsing -Uri 'https://<local_printer_ip>/tcp_setv4.cgi?W_IP8=4&W_IP10=0&W_IP11=1' -WebSession $temp_session -Method GET -SkipCertificateCheck
#Issue reset command to save config
Invoke-WebRequest -Uri 'https://<local_printer_ip>/reset.cgi?' -WebSession $temp_session -Method GET -SkipCertificateCheck
There are a few things to note in this so I’ll quick break them down:
- -SessionVariable creates the session to be used, -WebSession allows you to use the session later. Variable name can be whatever you’d like, but you do not use a $ during the setup.
- -UseBasicParsing was needed in my case I got a page not found error without it.
- The tcp_setv4 CGI command was found using the Developer Tools in my browser, and that’s how I’d suggest finding the command for anything else you’d want to modify.
- W_IP8 refers to the drop down menu, 1 = Manual/Static, 4 = Auto/DHCP
- W_IP10 refers to the Set Using Automatic Private IP Addressing (APIPA) setting and is required to issue the update.
- W_IP11 refers to the Set IP Address Using ARP + Ping setting and for Auto/DHCP needs to be set to 1, 0 would be Disable.
- If you need to do the opposite as I’ve done here, the command to update the printer to static is:
- https://<local_printer_ip>/tcp_setv4.cgi?W_IP8=1&W_IP1=<printer_ip>&W_IP2=<subnet_mask>&W_IP3=<gateway>&W_IP10=0&W_IP11=0
- E.g. https://192.168.1.213/tcp_setv4.cgi?W_IP8=1&W_IP1=192.168.1.10&W_IP2=255.255.255.0&W_IP3=192.168.1.1&W_IP10=0&W_IP11=0
- Remember to issue the reset command as that is seemingly what saves the config.
For my task, I included a few other things which included pulling in a list of printer IPs from a CSV, looping through that list and running the updates, sending the response HTTP codes to an array, and exporting that to a CSV. If you for some reason had your printers secured with different credentials, you could also include those in your initial CSV and build new credential objects during each loop.
Hope this has been helpful! And happy automating!