Script Daemon to Listen On a Port

How to test if a port is open or listening between two Solaris servers?

My problem is normal telnet <server> <port> does not work as nothing is listening on the port. 

Is there a script that would fake connect to this port for me to test the firewall via telnet host port? 

---

Create a script with lines like these, adjusting for your particular shell and *NIX of course. 

Save it at /var/tmp/port.script.bash. 

Set the execute bit: 

#!/bin/bash echo Executing my port script `date` >>/var/tmp/port.script.log echo Hello, welcome to the port script. ### end of script#!/bin/bash

echo Executing my port script `date` >>/var/tmp/port.script.log

echo Hello, welcome to the port script.

### end of script
 

Put a line in /etc/services for your port, or find the assigned name of the port. For argument/example here, let's say you are using the otherwise unassigned port 3121. (It's listed as unassigned in the file on my SLES 11 system at home...) 
 

Add a line: 

myport 3121/tcpmyport 3121/tcp

Then use the (x)inetd super-daemon to start listening on that port, executing the script on each connect. This will vary based on *NIX, but it is either a direct edit of /etc/inetd.conf or /etc/xinetd.conf, or adding a file to /etc/xinetd.d. 

You can follow the lead of what is there. Do a kill -HUP on the running (x)inetd process to reread its configuration and start listening to your port. The netstat -an command should show it listening. 
 

On AIX, edit /etc/inetd.conf, add line: 

myport stream tcp wait root /var/tmp/port.script.bash port.script.bash
 

On Linux, create the file /etc/xinetd.d/myport: 

service myport

{

socket_type = stream

protocol = tcp

wait = yes

user = root

server = /var/tmp/port.script.bash

}
 

Depending on the nature of the system being used for this "test" you may want to use a user other than root to execute the script on the port. Set permissions appropriately. 

Unix

See Also
Wrapper Scripts And Its Uses

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.