Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:02:02+00:00 2026-05-31T01:02:02+00:00

From a bash script how can I quickly find out whether a port 445

  • 0

From a bash script how can I quickly find out whether a port 445 is open/listening on a server.

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

It will be nice to know of a way that doesn’t enumerate first and greps after that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:02:03+00:00Added an answer on May 31, 2026 at 1:02 am

    A surprise I found out recently is that Bash natively supports tcp connections as file descriptors. To use:

    exec 6<>/dev/tcp/ip.addr.of.server/445
    echo -e "GET / HTTP/1.0\n" >&6
    cat <&6
    

    I’m using 6 as the file descriptor because 0,1,2 are stdin, stdout, and stderr. 5 is sometimes used by Bash for child processes, so 3,4,6,7,8, and 9 should be safe.

    As per the comment below, to test for listening on a local server in a script:

    exec 6<>/dev/tcp/127.0.0.1/445 || echo "No one is listening!"
    exec 6>&- # close output connection
    exec 6<&- # close input connection
    

    To determine if someone is listening, attempt to connect by loopback. If it fails, then the port is closed or we aren’t allowed access. Afterwards, close the connection.

    Modify this for your use case, such as sending an email, exiting the script on failure, or starting the required service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Automatic exit from bash shell script on error How can I have
I have a bash script that sources contents from another file. The contents of
I wrote a tiny Bash script to find all the Mercurial changesets (starting from
I have a Makefile from which I want to call another external bash script
I have written a very simple bash script to help me migrate from dev
In my bash script I have an external (received from user) string, which I
How can I run a command from a (bash) CGI script to play a
I'd like to have a Python script read stdin from the shell (bash), and
From a bash script how can i execute a perl script get the output
How can I extract the Qt version from a bash script using qmake -v

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.