Skip to content

Instantly share code, notes, and snippets.

@schorschii
Last active April 22, 2025 11:52
Show Gist options
  • Save schorschii/960cac86ad199a7c67722dec68e1beee to your computer and use it in GitHub Desktop.
Save schorschii/960cac86ad199a7c67722dec68e1beee to your computer and use it in GitHub Desktop.
(Re-)Configure the IP address of NETGEAR print servers.
#!/usr/bin/python3
# With this script, you can configure a new IP address for NETGEAR PS101(v2) print servers.
# Just connect the print server via Ethernet to your computer and execute the script,
# it will send an UDP packet over all of your network interfaces:
# ./netgear-ip-set.py PSxxxxxx 192.168.0.25 255.255.255.0 192.268.0.1
#
# Replace PSxxxxxx with your device name as printed on the back label of your device.
# It is not necessary to know the old IP address or to be in the same IP subnet with your computer;
# the NETGEAR device just needs to be in the same physical network or VLAN.
#
# Have fun.
import socket
import psutil
import argparse
import sys
def sendConfigPacket(deviceName, address, netmask, gateway):
ifaces = psutil.net_if_addrs()
gotResponse = False
msg = b'\x60\x00\x12\x00\x00\xc0\x02' + deviceName + netmask + gateway + address + b'\x0A'
for ifacename, iface in ifaces.items():
for snic in iface:
if(snic.family != socket.AF_INET): continue
viaAddress = snic.address
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.settimeout(4)
try:
if(viaAddress == '127.0.0.1'):
print(f'Sending config packet via default interface... ', end='', flush=True)
else:
print(f'Sending config packet via {viaAddress}... ', end='', flush=True)
sock.bind((viaAddress, 0))
sock.sendto(msg, ('255.255.255.255', 34443))
reply = sock.recv(5)
except Exception as e:
print(e)
continue
sock.close()
gotResponse = True
if(reply == b'\x60\x00\x00\x00\x00'):
print('OK! Got success response from device.')
sys.exit(0)
else:
print('unexpected response:', reply.hex())
sys.exit(2)
if(not gotResponse):
print()
print('Got no response from device! Is it properly connected, powered on and the device name correctly entered?')
sys.exit(3)
parser = argparse.ArgumentParser(description='Send IP config to NETGEAR PS101 printserver via UDP broadcast packet.')
parser.add_argument('device', help='The device name as printed on the label on the back of the device (PSxxxxxx)')
parser.add_argument('address', help='The IPv4 address to assign.')
parser.add_argument('netmask', help='The IPv4 netmask to assign.')
parser.add_argument('gateway', help='The IPv4 gateway to assign.')
args = parser.parse_args()
if(not args.device.startswith('PS')): raise Exception('Device name must start with "PS"')
if(len(args.device) != 8): raise Exception('Device name be 8 chars long')
devNameBytes = bytes.fromhex(args.device[2:])
addressSplitter = args.address.split('.')
if(len(addressSplitter) != 4): raise Exception('Invalid IPv4 address')
addressBytes = bytes([int(addressSplitter[0])])+bytes([int(addressSplitter[1])])+bytes([int(addressSplitter[2])])+bytes([int(addressSplitter[3])])
netmaskSplitter = args.netmask.split('.')
if(len(netmaskSplitter) != 4): raise Exception('Invalid IPv4 netmask')
netmaskBytes = bytes([int(netmaskSplitter[0])])+bytes([int(netmaskSplitter[1])])+bytes([int(netmaskSplitter[2])])+bytes([int(netmaskSplitter[3])])
gatewaySplitter = args.gateway.split('.')
if(len(gatewaySplitter) != 4): raise Exception('Invalid IPv4 gateway')
gatewayBytes = bytes([int(gatewaySplitter[0])])+bytes([int(gatewaySplitter[1])])+bytes([int(gatewaySplitter[2])])+bytes([int(gatewaySplitter[3])])
sendConfigPacket(devNameBytes,addressBytes, netmaskBytes, gatewayBytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment