How do you check a network port is open?
Forum: Networking
Topic: How do you check a network port is open?
started by: Juanito
Posted by Juanito on Sep. 16 2007,13:48
I'm trying to open up a network port in order to scan over the network. I added the following:
/etc/sources sane-port 6566/tcp # SANE network scanner daemon
/etc/inetd.conf sane-port stream tcp nowait dsl.staff /opt/hplip/sbin/saned saned
and then restarted /etc/init.d/inetd. So far things don't seem to be working - is there a way to check that the port is open from the same machine or another machine on the network? By telnet maybe?
Posted by roberts on Sep. 16 2007,14:54
Does by name:
# netstat -al
by number
# netstat -nl
help?
Posted by curaga on Sep. 16 2007,15:59
You could either try to telnet to that port from another machine, or just do a portscan..
Posted by Juanito on Sep. 17 2007,15:08
ThanksCode Sample | $ netstat -at Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:bootpc *:* LISTEN tcp 0 0 *:swat *:* LISTEN tcp 0 0 *:time *:* LISTEN tcp 0 0 *:sane *:* LISTEN tcp 0 0 *:discard *:* LISTEN tcp 0 0 *:vboxd *:* LISTEN tcp 0 0 *:daytime *:* LISTEN tcp 0 0 *:ipp *:* LISTEN | Looks promising.
But:Code Sample | $ telnet localhost 6566 Trying 127.0.0.1... Connected to box. Escape character is '^]'. Connection closed by foreign host. | albeit from the same machine.
and:Code Sample | c: telnet \192.168.1.100 6566 ...could not open connection to the host, on port 6566: Connect failed | from an xp machine, didn't look so promising.
Maybe this is an issue of user permissions?
Posted by curaga on Sep. 17 2007,15:14
..Or a firewall.. But if a port is open, telnetting to it will work, even from XP. For fun try "telnet google.com 80" and see what happens (if you wanna pretend to be a web browser, type "GET / HTTP/1.0" without the quotes and you'll see google front page get loaded)
Posted by Juanito on Sep. 17 2007,15:58
Well - both machines connect to google and from netstat, the sane port on 6566 looks to be open, but...
Posted by Juanito on Sep. 18 2007,12:16
I guess the solution (as it often is) was a matter of finding the correct error log to look in:Code Sample | $ scanimage -L [/var/log/messages] Sep 18 15:16:43 box daemon.err inetd[1572]: getpwnam: saned: No such user |
So, by changing the following (on the server as a test):
/etc/inetd.conf sane-port stream tcp nowait saned.saned /opt/hplip/sbin/saned saned --> --> sane-port stream tcp nowait root /opt/hplip/sbin/saned saned
/etc/saned/net.conf localhost
/etc/saned/dll.conf net hpaio
Then it all falls into place:Code Sample | $ sudo /etc/init.d/inetd restart $ telnet localhost 6566 Trying 127.0.0.1... Connected to box. Escape character is '^]'. ^] Connection closed by foreign host. $ scanimage -L device `hpaio:/usb/OfficeJet_K80?serial=ES0911401VOH' is a Hewlett-Packard OfficeJet_K80 all-in-one device `net:localhost:hpaio:/usb/OfficeJet_K80?serial=ES0911401VOH' is a Hewlett-Packard OfficeJet_K80 all-in-one $ scanimage -d net:localhost:hpaio:/usb/OfficeJet_K80?serial=ES0911401VOH --test scanimage: scanning image of size 638x1125 pixels at 24 bits/pixel scanimage: acquiring RGB frame, 8 bits/sample scanimage: reading one scanline, 1914 bytes... PASS scanimage: reading one byte... PASS scanimage: stepped read, 2 bytes... PASS ... |
Now to try it from dsl and winxp clients...
Posted by Juanito on Sep. 21 2007,07:12
Well... winxp doesn't want to scan remotely (so far), w2k works fine (and into photoshop via sanetwain - result) and it works from a remote dsl machine:Code Sample | $ telnet 192.168.1.100 6566 Trying 192.168.1.100... Connected to 192.168.1.100. Escape character is '^]'. ^] Connection closed by foreign host. $ export PATH=/opt/hplip/bin:/opt/python-2.3/bin:$PATH $ scanimage -L device `net:192.168.1.100:hpaio:/usb/OfficeJet_G85?serial=SGG13E0C49VL' is a Hewlett-Packard OfficeJet_G85 all-in-one $ scanimage --test scanimage: scanning image of size 638x877 pixels at 24 bits/pixel scanimage: acquiring RGB frame, 8 bits/sample scanimage: reading one scanline, 1914 bytes... PASS scanimage: reading one byte... PASS scanimage: stepped read, 2 bytes... PASS scanimage: stepped read, 4 bytes... PASS yada yada scanimage: stepped read, 3 bytes... PASS | ...not so fast over a wireless connection though
Posted by Juanito on Sep. 25 2007,15:14
...found the problem with winxp - something about the way it connects to saned (as compared to w2k) didn't like:Code Sample | $ cat /etc/sane.d/saned.conf 192.168.1.1/120 $ sudo /opt/hplip/sbin/saned -d128 [saned] main: starting debug mode (level 128) ... [saned] main: [1] bind () to port 6566 [saned] main: [1] listen () [saned] main: waiting for control connection [saned] saned (AF-indep+IPv6) from sane-backends 1.0.18 ready [saned] check_host: access by remote host: 192.168.1.102 [saned] check_host: remote host is not IN_LOOPBACK nor IN6_LOOPBACK [saned] check_host: local hostname: box [saned] check_host: local hostname(s) (from DNS): box [saned] check_host: remote host doesn't have same addr as local [saned] check_host: opening config file: saned.conf [saned] check_host: config file line: `192.168.1.1/120' [saned] check_host: subnet with base IP = 192.168.1.1, CIDR netmask = 120 [saned] check_v4_in_range: invalid CIDR value (120) ! [saned] init: access by host 192.168.1.102 denied [saned] quit: exiting
|
but naming the client ip address exlicitly did it:Code Sample | $ cat /etc/sane.d/saned.conf 192.168.1.102 192.168.1.1/120 $ sudo /opt/hplip/sbin/saned -d128 ... [saned] main: [1] bind () to port 6566 [saned] main: [1] listen () [saned] main: waiting for control connection [saned] saned (AF-indep+IPv6) from sane-backends 1.0.18 ready [saned] check_host: access by remote host: 192.168.1.102 [saned] check_host: remote host is not IN_LOOPBACK nor IN6_LOOPBACK [saned] check_host: local hostname: box [saned] check_host: local hostname(s) (from DNS): box [saned] check_host: remote host doesn't have same addr as local [saned] check_host: opening config file: saned.conf [saned] check_host: config file line: `192.168.1.102' [saned] check_host: access granted from IP address 192.168.1.102 [saned] init: access granted |
Its kind of odd that w2k doesn't have the same problem. Anyway, it works and the really good bit is that windows cannot share scanners natively...
|