Batch file to check the availability of a specific port of a remote server

user3506466

Hi I am trying to make a bat file to check the availability from different servers to a specific one, in order to check if there are some firewalls between them,or something that blocks the conecction. The thing is I can't use third parties software like portqry, nmap ... So iam stuck here, every tip will be helpfull.

Thanks in advance XD,

npocmaka

manually you can use telnet

echo.|telnet google.com 80

But telnet output cannot be handles so it's not useful for scripting.

Here's one solution which is more or less cheating (as it creates an .exe file) , but is not downloades. As it contains binary data into hex string it's a little bit long ,so I'd had to use pastebin.com

Another way.Using jscript.net/batch hybrid (should be saved as bat) which also creates a small exe file. But setting socket connection timeout is not so trivial task so if the port is not availble it will be waiting a little bit too long:

@if (@X)==(@Y) @end /****** silent line that start jscript comment ******

@echo off
::::::::::::::::::::::::::::::::::::
:::       compile the script    ::::
::::::::::::::::::::::::::::::::::::
setlocal
::if exist portchk.exe goto :skip_compilation

set "frm=%SystemRoot%\Microsoft.NET\Framework\"
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
        rem :: the javascript.net compiler
        set "jsc=%%~dpsnfxv\jsc.exe"
        goto :break_loop
    )
)
echo jsc.exe not found && exit /b 0
:break_loop


%jsc% /nologo /out:"portchk.exe" "%~dpsfnx0"
::::::::::::::::::::::::::::::::::::
:::       end of compilation    ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation

:: download the file


 ::::just change the link and the file::::
 portchk.exe google.com 80
 portchk.exe google.com 666


exit /b 0


****** end of jscript comment ******/

import System;
import System.Net.Sockets;
import System.Timers;

var arguments:String[] = Environment.GetCommandLineArgs();



var remote_host=arguments[1];
var remote_port=arguments[2];

//var ipa= (IPAddress) Dns.GetHostAddresses(remote_host)[0];

var sock=new System.Net.Sockets.Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

try {
    sock.Connect(remote_host, remote_port);
    //sock.ConnectAsync(remote_host, remote_port);
    timer_connection = new Timer();

    Console.WriteLine("connected to something");

}catch (e) {

    Console.WriteLine("Port is probably not available");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Batch file to check the availability of a specific port of a remote server

From Dev

Can't connect to remote server on specific port

From Dev

How do I check if a remote host is reachable at a specific port in C?

From Dev

How do I check if a remote host is reachable at a specific port in C?

From Dev

How to check if the current batch file is in a specific folder?

From Dev

How to check if i'm able to get to a remote server on a particular port

From Dev

Connect TcpClient to a remote Tcp server, binding to a specific local port

From Dev

Rsyslog not forwarding specific log file to remote server

From Dev

Rsyslog not forwarding specific log file to remote server

From Dev

Trying to check port availability with android app

From Dev

Bash Script to Check Port Availability with Timestamp

From Dev

ssh scp to copy file to remote server port 21

From Dev

Execute sftp commands on remote server using batch file and PuTTY

From Dev

SSH to a remote server using PuTTY through Windows batch file?

From Dev

Execute sftp commands on remote server using batch file and PuTTY

From Dev

java: Check if server has a specific file?

From Dev

How to test if a file check in remote server with ssh and if statement

From Dev

How to synchronise a specific file to a remote FTP server using lftp?

From Dev

launch mysqldump command to a remote server and save the backup file of mysqldump in the same remote server , in a specific folder

From Dev

How to download last modified file from remote server to local using PuTTY batch file

From Dev

How to check remote IP and Port is available?

From Dev

How to check remote IP and Port is available?

From Dev

Check if remote port is reachable using Centos

From Dev

tcp server not binding to specific port

From Dev

how to configure rsyslog to send file from specific program to specific location on remote server

From Dev

how to configure rsyslog to send file from specific program to specific location on remote server

From Dev

Execute commands using sudo in remote server after logging into PuTTY through batch file

From Dev

How to check if connected to remote server?

From Dev

Check directory exists on remote server

Related Related

  1. 1

    Batch file to check the availability of a specific port of a remote server

  2. 2

    Can't connect to remote server on specific port

  3. 3

    How do I check if a remote host is reachable at a specific port in C?

  4. 4

    How do I check if a remote host is reachable at a specific port in C?

  5. 5

    How to check if the current batch file is in a specific folder?

  6. 6

    How to check if i'm able to get to a remote server on a particular port

  7. 7

    Connect TcpClient to a remote Tcp server, binding to a specific local port

  8. 8

    Rsyslog not forwarding specific log file to remote server

  9. 9

    Rsyslog not forwarding specific log file to remote server

  10. 10

    Trying to check port availability with android app

  11. 11

    Bash Script to Check Port Availability with Timestamp

  12. 12

    ssh scp to copy file to remote server port 21

  13. 13

    Execute sftp commands on remote server using batch file and PuTTY

  14. 14

    SSH to a remote server using PuTTY through Windows batch file?

  15. 15

    Execute sftp commands on remote server using batch file and PuTTY

  16. 16

    java: Check if server has a specific file?

  17. 17

    How to test if a file check in remote server with ssh and if statement

  18. 18

    How to synchronise a specific file to a remote FTP server using lftp?

  19. 19

    launch mysqldump command to a remote server and save the backup file of mysqldump in the same remote server , in a specific folder

  20. 20

    How to download last modified file from remote server to local using PuTTY batch file

  21. 21

    How to check remote IP and Port is available?

  22. 22

    How to check remote IP and Port is available?

  23. 23

    Check if remote port is reachable using Centos

  24. 24

    tcp server not binding to specific port

  25. 25

    how to configure rsyslog to send file from specific program to specific location on remote server

  26. 26

    how to configure rsyslog to send file from specific program to specific location on remote server

  27. 27

    Execute commands using sudo in remote server after logging into PuTTY through batch file

  28. 28

    How to check if connected to remote server?

  29. 29

    Check directory exists on remote server

HotTag

Archive