Sponsored Content
Full Discussion: Perl- check the port used
Top Forums Shell Programming and Scripting Perl- check the port used Post 302523522 by bassma on Thursday 19th of May 2011 04:41:41 AM
Old 05-19-2011
Error Perl- check the port used

hi everybody;
my code is cheking if a port is an actif or not with the cmd netstat -ln,I want first to enter the number of the port which I want to check it but I think that the value of $con in the second "if" is always "0" so the code give me always that the port is not used!!!

Code:
#!/usr/bin/perl
print "enter the port :\n";
$port=<STDIN>;
$con=0;
open (FILE,"-|") exec "netstat -ln |grep" .$port;
open (FIL,">res.txt");
whiel (<FILE>){
if ($_ =~/:$port/){$con++;}}
if ($con){
print FIL "The active port is : $port\n"}
else{
print FIL "the port is not active\n";}
close FIL;
close FILE;

 

10 More Discussions You Might Find Interesting

1. IP Networking

how can i check if port is busy or if someone is using it ?

Hello i have application that using ports , how can i check if the port im using is not captured by any applications? (1 Reply)
Discussion started by: umen
1 Replies

2. IP Networking

How can I check what port addresses used the application

Hello Mentors! I am a new here in the furom, i hope somebody can understand my problem. Basically we have an application here called unigraphics and being installed per station and the setup is look like this. 1. installed unigraphics UGNX3 version on every station 2. some are installed in... (1 Reply)
Discussion started by: eykyn17
1 Replies

3. Solaris

How to check that a device is attached on a port

Q1: can anyone tell me how cfgadm keeps track of the device even if the device is disconnected , when we disconnect a device using cfgadm cfgadm -ys disconnect <ap_id> then the device disappears from the lshal o/p. HAL uses libdevinfo for the device list. if the device is not there in the... (2 Replies)
Discussion started by: narendra.pant
2 Replies

4. UNIX for Dummies Questions & Answers

How do you check whether a port currently being used?

Hi, Please help me out, how to check whether a port currently being used or not. is there any command which give the result? Thanks Rajesh (6 Replies)
Discussion started by: rajesh08
6 Replies

5. Shell Programming and Scripting

How to check if a Port is accepting connections.

Hi, I need to create a script which checks the availability of a particular service on a particular Port on HP-Unix. Is there any command in unix wherein we can check if any port is accepting the connections now. Thanks, Vihang. (5 Replies)
Discussion started by: vikings.svnit
5 Replies

6. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

7. Shell Programming and Scripting

How to check UDP port example = 31011?

We have open port UDP port 31011, how to verify if port were working or traffic were receive. (2 Replies)
Discussion started by: avtalan
2 Replies

8. Red Hat

How to check port used for SSL?

I have RHEL 5.8 in our production environment. We are using SSL, my query is how to find the port used for SSL. In /etc/services, it shows 443 but when I give netstat -tulpn | grep 443 Or netstat -tulp | grep https I do not get any output. I hope, my question is clear of how to find... (4 Replies)
Discussion started by: RHCE
4 Replies

9. Shell Programming and Scripting

How to check empty port using netstat?

Hi, How to check empty port using netstat please help Thanks Ashfaque (3 Replies)
Discussion started by: ashfaque
3 Replies

10. Shell Programming and Scripting

How to check the IP:PORT firewall uses?

I have my firewall process running # ps -ef | grep firewall root 21169 1 0 08:50 ? 00:00:00 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid I wish to know what ip : port number it is using. Can you please tell me how can i find out ? I tried the below command... (4 Replies)
Discussion started by: mohtashims
4 Replies
UMAD_GET_PORT(3)					    OpenIB Programmer's Manual						  UMAD_GET_PORT(3)

NAME
umad_get_port, umad_release_port - open and close an InfiniBand port SYNOPSIS
#include <infiniband/umad.h> int umad_get_port(char *ca_name, int portnum, umad_port_t *port); int umad_release_port(umad_port_t *port); DESCRIPTION
umad_get_port() fills the port structure with the IB port attributes specified by ca_name and portnum , or the default port if ca_name is NULL and portnum is zero. If only one of ca_name and portnum are specified, the other is used as a filter. For example, passing a NULL ca_name and 2 for the portnum means get a port from any of the local IB devices, as long as it is the second port. Note that the library may use some reference scheme to support port caching therefore umad_release_port() should be called before the port structure can be deal- located. The argument port is an umad_port_t struct, as specified in <infiniband/umad.h>. typedef struct umad_port { char ca_name[UMAD_CA_NAME_LEN]; /* Name of the device */ int portnum; /* Physical port number */ uint base_lid; /* Base port LID */ uint lmc; /* LMC of LID */ uint sm_lid; /* SM LID */ uint sm_sl; /* SM service level */ uint state; /* Logical port state */ uint phys_state; /* Physical port state */ uint rate; /* Port link bit rate */ uint64_t capmask; /* Port capabilities */ uint64_t gid_prefix; /* Gid prefix of this port */ uint64_t port_guid; /* GUID of this port */ } umad_port_t; umad_release_port() releases the resources that were allocated by the umad_get_port() function for the specified IB port. RETURN VALUE
umad_get_port() and umad_release_port() return 0 on success, and a negative value on error. AUTHORS
Hal Rosenstock <halr@voltaire.com> Dotan Barak <dotanb@mellanox.co.il> OpenIB May 21, 2007 UMAD_GET_PORT(3)
All times are GMT -4. The time now is 02:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy