Skip to content

Instantly share code, notes, and snippets.

@schorschii
Last active May 4, 2026 12:46
Show Gist options
  • Select an option

  • Save schorschii/d9f498af5aecfa9c5aed054bde116a88 to your computer and use it in GitHub Desktop.

Select an option

Save schorschii/d9f498af5aecfa9c5aed054bde116a88 to your computer and use it in GitHub Desktop.
Add, delete and list scan targets on a Ricoh device (M 320FSE), automated via script to avoid the crappy web UI
#!/bin/python3
import requests
import argparse
import os
def checkResponse(r):
if(r.status_code != 200):
raise Exception('Unexpected status code '+str(r.status_code))
if('Wrong Password' in r.text):
raise Exception('Wrong Password')
def addProfile(host, adminpw, name, destination_email, notification_email, subject):
r = requests.post(f'https://{host}/form/profileAdd', verify=False, data={
'admin': adminpw,
'type': 1,
'QuickDial': '',
'Density': 3,
'reqdestname': name,
'name1': name,
'reqdestname2': name,
'history': '',
'normal': 1,
'Forwarding': '',
'upd': 1,
'oldname': '',
'reqemailaddr': destination_email,
'emailaddr1': notification_email,
'reqSubject': subject,
'emailkeyname': '',
'fileformatcolor': 1, # 1=PDF, 0=JPEG
'fileformat': 1, # 2=TIFF, 1=PDF
'resolution': 4, # 1=100dpi, 2=150dpi, 3=200dpi, 4=300dpi, 5=400dpi, 6=600dpi
'Original': 0, # 0 = 1 Sided
# 2 = 2 Sided Portrait: Top to Top
# 3 = 2 Sided Portrait: Top to Bottom
# 4 = 2 Sided Landscape: Top to Top
# 5 = 2 Sided Landscape: Top to Bottom
'docSize': 3, # 1=A5, 2=B5, 3=A4, 4=7¼x10½, 5=8½x5½, 6=8½x11, 7=8½x14, 9=16K, 8=Custom
# following params are for custom docSize only
'unit': 0, # 0=mm, 1=inch
'widthmm': 210,
'lengthmm': 297,
'widthinch1': 8,
'widthinch2': 50,
'lengthinch1': 11,
'lengthinch2': 00,
})
checkResponse(r)
def delProfile(host, adminpw, name):
r = requests.post(f'https://{host}/form/frm_Delete', verify=False, data={
'admin': adminpw,
'type': 1,
'Modify': 1,
'Pname': name,
'Density': 3,
'history': '',
'normal': 1,
'Forwarding': '',
})
checkResponse(r)
def listProfile(host, adminpw):
r = requests.post(f'https://{host}/scanmail.asp', verify=False, data={})
checkResponse(r)
from lxml import etree
tables = etree.HTML(r.text).iter('table')
for table in tables:
rows = iter(table)
headers = [col.text for col in next(rows)]
if(len(headers) != 4): continue
for row in rows:
print(row[1].text + "\t" + row[3].text)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('action', help='add | del | list')
parser.add_argument('--name', help='Entry name')
parser.add_argument('--destination-email', help='Entry destination email address')
parser.add_argument('--notification-email', help='Entry notify email address')
parser.add_argument('--subject', help='Entry email subject')
parser.add_argument('--adminpw', help='Admin password (you can also set RICOH_ADMINPW environment variable)', default=os.environ.get('RICOH_ADMINPW', ''))
parser.add_argument('--host', help='Printer address (you can also set RICOH_HOST environment variable)', default=os.environ.get('RICOH_HOST', ''))
args = parser.parse_args()
if(args.action == 'add'):
if(addProfile(
args.host, args.adminpw,
args.name, args.destination_email, args.notification_email, args.subject
)): print('OK')
elif(args.action == 'del'):
if(delProfile(
args.host, args.adminpw,
args.name
)): print('OK')
elif(args.action == 'list'):
if(listProfile(
args.host, args.adminpw
)): print('OK')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment