0

My friends and I play Unturned and everyday someone else hosts the server. I would like to make a batch file that checks if the server is already running on someone else's PC. We sync our server files using Dropbox. This means files could get corrupted if multiple people started the server at the same time.

Program structure:

@echo off
// Check if the server is already hosted elsewhere
if already_hosted
     echo Server is already hosted on {IP}.
else
     start server.exe
TypicalHog
  • 175
  • 1
  • 3
  • 12

1 Answers1

1

I would use netstat -na |findstr ":27015.*LISTEN" and if the errorlevel is 0 that means it's running, if it's not 0 it means it's not running. You don't need any external programs that don't come with Windows, not even CLI ones like portqry.

netstat -na |findstr ":27015.*LISTEN"
if errorlevel 1 start server.exe
theglossy1
  • 543
  • 3
  • 13