Script to bind to socket


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to bind to socket
# 1  
Old 02-24-2013
Script to bind to socket

i need to come up with a script that when run from the command line, it will bind to a socket, and listen for tcp connections on a certain port.

something like:

Code:
### ./connection_listener 5666


i found the following script on the web but when i run it, it complains about "accept" not being available.

Code:
perl -MIO::Socket::INET -ne 'BEGIN{$l=IO::Socket::INET->new(
  LocalPort=>5666,Proto=>"tcp",Listen=>5,ReuseAddr=>1);
  $l=$l->accept}print $l $_'

OS: Linux/SunOS/HPUX/AIX
# 2  
Old 02-24-2013
NetCat is best for that...

I endorse using netcat for this.
"nc -l 3343 " begins listening on port 3343. I've used this to tie serial to TCP/IP, strait TCP/IP, etc. See
http://www.g-loaded.eu/2006/11/06/ne...seful-examples

Smilie

Last edited by jim mcnamara; 02-24-2013 at 04:04 PM..
This User Gave Thanks to MattyV For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Script to check if user can bind, then output to file

Hi, I've been trying to find the answer with no luck. I'm hoping someone can help me. Here's what I need to do: Run a KSH script that will check: 1. Server (Client) Type (AIX 5.3, 6.1, SUSE, and HP-UX are the possibilities). 2. LDAP.cfg is configured correctly and the ldap client... (3 Replies)
Discussion started by: tekster2
3 Replies

2. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

3. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

4. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

5. Shell Programming and Scripting

shell script: Bind variable not declared

Hi Friends, I am trying to run a sql query from shell script as below but I get "Bind variable "1" not declared" error. 1.sh shell script has following: sDb="abc/xyz@aaa" a="1.sql" sqlplus -s $sDb @$a $1 1.sql file has following: spool Result.tmp append select cust_name from orders... (1 Reply)
Discussion started by: ppat7046
1 Replies

6. Programming

GetLastError API for socket/bind failure in VxWorks 5.4

Can anyone tell what is the system API for VxWorks which is used to find GetLastError() for socket/bind failure. I need to use it in some VxWorks application and need to call GetLastError but I'm not sure about the correct API. Thanks in advance (1 Reply)
Discussion started by: anilgurwara
1 Replies

7. UNIX for Dummies Questions & Answers

permission to bind a socket to port 843?

I have written a flash socket security file server in PHP. The basic idea is that when Flash Player connects via socket to a server, the first thing it does is connect to port 843 and send a request for a 'socket policy file' by sending the string <policy-file-request/>. The problem I have is... (5 Replies)
Discussion started by: sneakyimp
5 Replies

8. Shell Programming and Scripting

Help needed with script to verify the version of BIND

I have tried thought of using instfix -ivqc | grep BIND , but this did not return the result I was looking for; it seem to list out the the different patches that had been applied to BIND. I'm actually looking for overall version, like you'd get when checking the OS level for instance. (1 Reply)
Discussion started by: sport
1 Replies

9. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

10. UNIX for Dummies Questions & Answers

Socket bind fails

Hi, 1 more new comer with a small problem. I have a Java socket program which tries to bind to a particular socket. It works fine with windows. But in Linux, it says 'address in use'. I tried 'netstat' to find if the port is being used. But it is free. Can anyone help plz? (0 Replies)
Discussion started by: ronyantony
0 Replies
Login or Register to Ask a Question