Check For Open Port with If then statement

Welcome Forums General PowerShell Q&A Check For Open Port with If then statement

This topic contains 1 reply, has 2 voices, and was last updated by

2 years ago.

  • Author
  • #63886

    Points: 0
    Rank: Member

    Hi Forum. I need help putting code together. I'm trying to check a specific local tcp port is open (in this case port 3306). if it's closed i'd like to open it.

    If the port is open, echo "port is open.."
    else, if port is closed, open port.

    this seems like a pretty straightforward code yet, i'm stumped..

  • #63893

    Points: 26
    Rank: Member

    I would suggest you to look into some cmdlets that will let you interact with the Firewall. Like Get-NetFirewallRule and Get-NetFirewallPortFilter. Try to see what you can get back with it, and try to use it to do your check.

    btw: if you would have used Get-Command get*firewall*, you would have found a lot of firewall related cmdlets.

The topic ‘Check For Open Port with If then statement’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort