Today : Wed, 25 May 16 .


Dag Rende


ScanToFolder

Page: Main.ScanToFolder - Last Modified : Fri, 17 Oct 08

Scan-to folder on Linux

This function is simple to use - put something in the scanner and push the "Scan to" button and then the "Start Scanning" button. The scanner scans and sends the result to a file in a folder in a server on your local network. You can also have multiple folders on the server that you can select on the printer before scanning.

Hidden pages

By using Wireshark I listened to the traffic on the net when using this function from a windows machine. The result was much simpler that I suspected.

The printer is a web server that you can access with a web browser - this is documented in the manual. But there are some undocumented web addresses that can be used to detect the Scan-to-button and other things. Here are som examples:

My printer has ip address 192.168.0.43, so change to the ip of your printer in these examples.

There are also addresses for changing things:

(see below for more protocol details)

Destination list utility

I wrote a utility bash script for maintaining the list of scan-to destinations in the printer.

./scanto_destination -lLists all destinations in the printer.
./scanto_destination -a <destname>Adds a new destination name, where <destname> can be name or host:name.
./scanto_destination -d <destname>Deletes a destination name.

Note that the destination list is stored in the printer and is cleared when the printer is restarted.

Example output on my system:

 ./scanto_destination -l
 gong2:color150
 gong2:color300
 gong2:color75

scanto_destination:

#!/bin/bash
# command to maintain the scan-to destination list in the HP Color LaserJet 2840 printer
if [ "$1" == "-a" ]; then
	name=$2
	[[ ! "$name" =~ ":" ]]&& name="$HOSTNAME:$name"
	postdata="AddScanToDest_1=127.0.0.1-$HOSTNAME%5e${name/:/%3a}%5eDestFolder"
	wget -q -O - --post-data="$postdata" http://192.168.0.43/hp/device/set_config.html
elif [ "$1" == "-d" ]; then
	name=$2
	[[ ! "$name" =~ ":" ]]&& name="$HOSTNAME:$name"
	postdata="RemoveScanToDest_1=${name/:/%3a}"
	wget -q -O - --post-data="$postdata" http://192.168.0.43/hp/device/set_config.html
elif [ "$1" == "-l" ]; then
	wget -q -O - http://192.168.0.43/hp/device/info_scanto_destinations.xml \
	| sed -n '/<DeviceDisplay>/s/<\/*DeviceDisplay>//gp'
else
	echo 'usage: scanto_destination -l -a <destname> -d <destname> for listing adding and deleting destinations'
fi

A Linux scanner server

The following bash script is a loop that checks each 5 seconds if the scan-to button has been pressed, and then makes a scan according to the destination selected on the printer. The scan is performed by a script named after the destination. the scan result is placed in the scans folder and the scan command scripts are in the scan-command folder.

The server also checks if the scan-to destinations in the printer are the same as the command files in the sca-command directory, and adds or deletes destinations in the printer if they don't match.

scanloop:

#!/bin/bash
cd "`dirname $0`"
set -o pipefail
while true; do
	# if scan-to button pressed - run the command corresponding to the destination name
	name=`wget -q -O - http://192.168.0.43/hp/device/notifications.xml \
			| egrep -o '<ScanToDeviceDisplay>(.*)</ScanToDeviceDisplay>' \
			| sed -e 's/<ScanToDeviceDisplay>//' \
			| sed -e 's/<\/ScanToDeviceDisplay>//' \
			| sed -e 's/.*://'` && {
		if [ "$name" != "" ]; then
			if [ -x "scan-command/$name" ]; then
				(cd scans; "../scan-command/$name" >/dev/null 2>&1)
				chmod a+r scans/*
			fi
		fi
	}

	# update scan-to destinations in printer if necessary
	./scanto_destination -l | sed  's/.*://' >/tmp/printer-dests &&
	ls scan-command >/tmp/command-dests &&
	diff /tmp/printer-dests /tmp/command-dests | egrep '<|>' | 
	  sed 's#<#./scanto_destination -d#;s#>#./scanto_destination -a#' | bash

	sleep 5
done

scan-command/color75:

hp-scan -n -r75

scan-command/color150:

hp-scan -n -r150

scan-command/color300:

hp-scan -n -r300

Protocol details

http://192.168.0.43/hp/device/notifications.xml - no Scan-to in progress

The following document is returned:

<?xml version="1.0" encoding="UTF-8"?>
<Notifications>
  <ScanToNotifications>
    <ScanToDeviceDisplay/>
    <ScanToHostID/>
    <ScanToNotSetup>0</ScanToNotSetup>
    <ADFLoaded>0</ADFLoaded>
  </ScanToNotifications>
  <StartScanNotifications>
    <StartScan>0</StartScan>
    <ADFLoaded>0</ADFLoaded>
  </StartScanNotifications>
  <FaxNotifications>
    <FaxReceiveFunction>1</FaxReceiveFunction>
    <FaxPrinting>0</FaxPrinting>
    <FaxMasterHostID/>
    <FaxUploadState>1</FaxUploadState>
    <FaxLogChangeIndicator>0</FaxLogChangeIndicator>
    <FaxForwardEnabled>0</FaxForwardEnabled>
    <FaxForwardNumber/>
  </FaxNotifications>
</Notifications>

http://192.168.0.43/hp/device/notifications.xml - Scan-to in progress

The selected Scan-to destination is tpw:TPW.

<?xml version="1.0" encoding="UTF-8"?>
<Notifications>
  <ScanToNotifications>
    <ScanToDeviceDisplay>tpw:TPW</ScanToDeviceDisplay>
    <ScanToHostID>127.0.0.1-tpw</ScanToHostID>
    <ScanToNotSetup>0</ScanToNotSetup>
    <ADFLoaded>0</ADFLoaded>
  </ScanToNotifications>
  <StartScanNotifications>
    <StartScan>0</StartScan>
    <ADFLoaded>0</ADFLoaded>
  </StartScanNotifications>
  <FaxNotifications>
    <FaxReceiveFunction>1</FaxReceiveFunction>
    <FaxPrinting>0</FaxPrinting>
    <FaxMasterHostID/>
    <FaxUploadState>1</FaxUploadState>
    <FaxLogChangeIndicator>0</FaxLogChangeIndicator>
    <FaxForwardEnabled>0</FaxForwardEnabled>
    <FaxForwardNumber/>
  </FaxNotifications>
</Notifications>

http://192.168.0.43/hp/device/info_scanto_destinations.xml

The scan-to destinations are tpw:TPW and tpw:TPW2.

<?xml version="1.0" encoding="UTF-8"?>
<ScanToDestinations>
  <MaxScanToDestinations>30</MaxScanToDestinations>
  <AvailableScanToDestinations>28</AvailableScanToDestinations>
  <ScanToDestinationList>
    <ScanToDestination DestinationID="0">
      <HostID>127.0.0.1-tpw</HostID>
      <DeviceDisplay>tpw:TPW</DeviceDisplay>
      <ScanToType>DestFolder</ScanToType>
    </ScanToDestination>
    <ScanToDestination DestinationID="1">
      <HostID>127.0.0.1-tpw</HostID>
      <DeviceDisplay>tpw:TPW2</DeviceDisplay>
      <ScanToType>DestFolder</ScanToType>
    </ScanToDestination>
  </ScanToDestinationList>
</ScanToDestinations>

http://192.168.0.43/hp/device/set_config.html

To add the scan-to destination tpw:TPW2, POST the following string to this address:

AddScanToDest_1=127.0.0.1-tpw%5etpw%3aTPW2%5eDestFolder

Make sure you have supplied the correct CONTENT-LENGTH header. In this case CONTENT-LENGTH:55. I'm not sure about the 127.0.0.1-tpw, but it appears to represent the ip and host name of the sender.

To remove the scan-to destination tpw:TPW2, POST string:

RemoveScanToDest_1=tpw%3aTPW2

Powered by PmWiki
Skin by CarlosAB

looks borrowed from http://haran.freeshell.org/oswd/sinorca
More skins here