LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2005, 08:56 AM   #1
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Rep: Reputation: 15
ports used


is there a way via bash script that i can get the ports in a range say 12200 13000 that are being used by a user and storing them in a variable

so that when i write the variable to a file it just lists the port numbers used


thanks
 
Old 11-22-2005, 09:59 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Set ipv4 ports of user xxx from p1 to p2 in var


Code:
var=`lsof -n -i4:$p1-$p2 -a -u$xxx | awk '/IPv4/ {print $8}' | cut -d':' -f2 | cut -d'-' -f1 | sort | uniq | tr '\n' ' ' `
Does the trick but very ugly, it should be possible in one regular expression

Last edited by nx5000; 11-22-2005 at 10:01 AM.
 
Old 11-22-2005, 10:45 AM   #3
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Original Poster
Rep: Reputation: 15
these ports are made by games running will this still work and i have tried it but comes up with

lsof command not found
 
Old 11-22-2005, 11:01 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
How about installing "lsof"?
 
Old 11-22-2005, 01:15 PM   #5
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
You can use netstat command too, netstat -vatn | grep port
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Open Mail Server Ports 25, 110, and 220. Other Ports will open. Binxter Linux - Newbie 9 11-29-2007 02:03 AM
need help with ports alagenchev Linux - Security 5 10-22-2005 07:29 PM
all ports down chiggly Linux - Newbie 10 10-16-2005 06:09 PM
? about ports bwoodwar Linux - Networking 3 09-19-2005 04:33 PM
ports Pedroski Linux - Newbie 5 11-20-2004 03:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration