Check open ports every ...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check open ports every ...
# 1  
Old 08-02-2005
Question Check open ports every ...

Hello, i need a script (bash type maybe?..), which would check open ports on 127.0.0.1 and then compare open ports with "registered/allowed" port list and try to kill the program who uses unregistered ports. It would be great that script would be started lets say every 5 or 10 minutes.

You see i would like to have some kind of script which would allow me to control other users that they don't leave their psybnc, eggdrops and so on.

Thanks...
# 2  
Old 08-03-2005
You could use the 'lsof' command to check what process is listening on a particular port, but it is a bit slow so you wont be able to run the script every 5 minutes (all the ports wont be scanned by then).
# 3  
Old 08-03-2005
Here ya go

Provided you have netcat installed, this should run pretty quickly.

Code:
for port in {1..65536}; do
    nc -zv 127.0.0.1 $port 2>&1
done | grep open

Netstat will also tell you what programs have open listening tcp ports. On a linux system, it would go something like this:

Code:
netstat -l -t -p


Last edited by vertigo23; 08-03-2005 at 05:23 PM..
This User Gave Thanks to vertigo23 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check unused ports in a given range and assign an open one

Hi. I need to add code to my KSH script to automatically assign an open port number from a pre-defined range to an Oracle listener. Should I use: lsof -i or netstat -vatn or something else? Thanks. (9 Replies)
Discussion started by: user052009
9 Replies

2. IP Networking

Open/close of ports

Hi, I have read some forum theads about the open and close ports. some points are clear and it is not working on my machine or something am i missing? I have commented out a port /etc/services, one application uses then when i use the telnet <hostname> <port_blocked> it shows connected..... (1 Reply)
Discussion started by: balamv
1 Replies

3. UNIX for Dummies Questions & Answers

open ports and services

just a quick question: a. whats the simplest command to check open port and the corresponding services? example: bash-2.05# netstat -an | grep LISTEN *.199 *.* 0 0 49152 0 LISTEN *.8989 *.* 0 0 49152 ... (1 Reply)
Discussion started by: lhareigh890
1 Replies

4. Solaris

Open ports in solaris 10

hi guys, may i know the exact steps to open a port in solaris.i have some rough idea - which is adding the port number in /etc/services. but i am not sure the correct conventions, steps or any other steps. kindly advise.thanks guys ! (1 Reply)
Discussion started by: cromohawk
1 Replies

5. Solaris

open ports solaris 8

Hello, I have a number of Solaris 8 Sun servers that have open ports that I cannot identify. I see some with 1013-1023 (which are reserved ports according to the IANA. Lsof does not identify these. I rebooted the server and they went off, but this morning I saw they were all back on again. Any... (1 Reply)
Discussion started by: csgonan
1 Replies

6. UNIX for Dummies Questions & Answers

open ports solaris 8

Hello, I have a number of Solaris 8 Sun servers that have open ports that I cannot identify. I see some with 1012-1020 (which are reserved ports according to the IANA. Lsof does not identify these. One server has all these on and one server just has 1017. *.1023 ... (3 Replies)
Discussion started by: csross
3 Replies

7. AIX

Open Ports on System

Hi Every body, What is the command on AIX 5.2 that can be used to get all open ports? (2 Replies)
Discussion started by: aldowsary
2 Replies

8. UNIX for Advanced & Expert Users

determining open ports

hi all 1) how to determine available ports in a box (solaris) do i have to go for a netstat on all the ports? 2) how to block a particular port for a particular type of connection. Any help would be greatly appreciated Thanks (7 Replies)
Discussion started by: matrixmadhan
7 Replies

9. Linux

How To Open Ports in RedHat ?

how can i open ports i need in red hat server vs root access ? (7 Replies)
Discussion started by: Sirius
7 Replies

10. Cybersecurity

closing open ports

/* Linux Slackware */ Nmap shows the following ports open on the gateway. 21/tcp ftp 22/tcp ssh 23/tcp telnet 25/tcp smtp 37/tcp time 80/tcp http 113/tcp auth 515/tcp printer 587/tcp submission 1024/tcp kdm 6000/tcp x11 ------------------------------- i would like to close as... (10 Replies)
Discussion started by: LowOrderBit
10 Replies
Login or Register to Ask a Question