Linux: Efficiently test if a port is Open

0 votes
How can I quickly find out whether a port 445 is open/listening on a server from a bash script.

I have tried a couple of options, but I want something quick:
1. lsof -i :445 (Takes seconds)
2. netstat -an |grep 445 |grep LISTEN (Takes seconds)
3. telnet (it doesn't return)
4. nmap, netcat are not available on the server

Is there another way that doesn't enumerate first and greps after that.
Jun 12, 2019 in Linux Administration by Upasana
• 8,570 points
44 views

1 answer to this question.

0 votes
$ nc -z <host> <port>; echo $?

Use this with 127.0.0.1 as "remote" address.
answered Jun 12, 2019 by Shubham
• 13,370 points

Related Questions In Linux Administration

0 votes
1 answer

Linux: Killing a process occupying a particular port

Use the port command to find the ...READ MORE

answered Apr 3, 2019 in Linux Administration by DareDev
• 6,830 points
59 views
0 votes
1 answer

Determining whether a given Linux is 32 bit or 64 bit

try this. getconf LONG_BIT Output: 32, if OS is 32 ...READ MORE

answered May 21, 2019 in Linux Administration by Upasana
• 8,570 points
37 views
0 votes
1 answer

Which is a good hex editor for Linux?

You could try Bless. It is written ...READ MORE

answered Jun 4, 2019 in Linux Administration by Upasana
• 8,570 points
60 views
0 votes
1 answer

How to create a symlink in Linux?

To create a symbolic link, you can ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 68,860 points
84 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Adding yes/no/cancel prompts in shell script

You can use the read command. Here's ...READ MORE

answered Mar 12, 2019 in Linux Administration by ajs3033
• 7,280 points
62 views
0 votes
1 answer

How to change the default shell in Linux?

1. Change the password file directly for ...READ MORE

answered May 24, 2019 in Linux Administration by Upasana
• 8,570 points
46 views
0 votes
1 answer
0 votes
1 answer

Comparing two string variables in an 'if' statement in Bash

1. For string comparison, use: if [ "$s1" ...READ MORE

answered May 15, 2019 in Linux Administration by Shubham
• 13,370 points
78 views