Does anybody know a "Single-EXE" command line port scanner?

Hi.

[color=blue]

Not sure if you would want to deploy perl?[/color]

Nope, if you mean, if I want to deploy it on each and every client box.

[color=blue]

This works for sure (reduce the timeout to 1 second on line 54);
http://exchange.nagios.org/directory/Plugins/Network-Protocols/*-TCP-and-UDP-(Generic)/check_port-2Epl/details[/color]

Is it possible to COMPILE perl scripts to a single EXE?

Regards, Rudi.

Hi Hamish,

[color=blue]

I have a utility to check if a port is open, but it waits for the
timeout that you’ve run into. I’ll see if I can re-do it as a
non-blocking socket - that should allow for user defined timneout.[/color]

How are the chances for a user defined timeout?

Thanks for your reply, Rudi.

On 12/12/2012 4:09 AM, Rudolf Thilo wrote:[color=blue]

Hi Hamish,

[color=green]

I have a utility to check if a port is open, but it waits for the
timeout that you’ve run into. I’ll see if I can re-do it as a
non-blocking socket - that should allow for user defined timneout.[/color]

How are the chances for a user defined timeout?[/color]

Rudi,

user defined timeout was the whole idea :slight_smile: And it is working.

usage is:

chkport-ip x.x.x.x port timeout

where:

  • x.x.x.x is the target IP address
  • port is port to connect to.
  • timeout is the time out in millisecs to wait.

so: chkport-ip 8.8.8.8 53 100

checks to see if it can connect to Googles DNS service in 100 msecs.
(BTW - it can, but at 10 msec it times out).

If you want to send me an email at hamish at haitch dot net with an
email address that can accept executables, I’ll send it to you.

H.

[color=blue]

usage is:

chkport-ip x.x.x.x port timeout

where:

  • x.x.x.x is the target IP address
  • port is port to connect to.
  • timeout is the time out in millisecs to wait.

so: chkport-ip 8.8.8.8 53 100

checks to see if it can connect to Googles DNS service in 100 msecs.[/color]

Can be downloaded from:

https://www.dropbox.com/s/gpn0vxc36whxqpn/chkport-ip.exe

H.

Hi Haitch,

that’s exactly what I was looking for:
[color=blue]

https://www.dropbox.com/s/gpn0vxc36whxqpn/chkport-ip.exe[/color]

  • single exe file
  • adjustable timeout
  • exit code reflecting the result.

Did you write that tiny, nice tool?

PERFECT! Thanks a lot,

regards, Rudi.

Rudi,
[color=blue]

that’s exactly what I was looking for:
[color=green]

https://www.dropbox.com/s/gpn0vxc36whxqpn/chkport-ip.exe[/color]

  • single exe file
  • adjustable timeout
  • exit code reflecting the result.[/color]

Glad you like it - if there are any tweaks you’d like, let me know.[color=blue]

Did you write that tiny, nice tool?[/color]

Yep. In Pascal … And one of these days I’ll clean the code up and
port it over to the version that does name resolution rather than
requiring IP addresses.
[color=blue]

PERFECT! Thanks a lot,[/color]

You’re welcome.

H.

Hi Hamish,

I’m wondering, whether I should drop a feature request at the
developers forum of Autoit, to implement “non-blocking sockets” as
well. As I have no clue, how you did that trick: Would you mind to
share the source, so that I could point them to your code to see, how
it’s done / how much work this might be?

If that’s OK for you…

One feature that might be nice would be the option to specify the
protocol as well, e.g. UDP:69, or icmpv4:8 [1 → PING]

But this is just an idea, not something I currently need (and,
honestly, I have no clue at all, how much work these features might be)

Regards, Rudi.

[1]
for allowing incoming ICMP ECHO requests I found this netsh somewhere
in the web:

netsh advfirewall firewall add rule name=“ICMP Allow incoming V4 echo
request” protocol=icmpv4:8,any dir=in action=allow

On 12/18/2012 8:15 AM, Rudolf Thilo wrote:
[color=blue]

Hi Hamish,

I’m wondering, whether I should drop a feature request at the
developers forum of Autoit, to implement “non-blocking sockets” as
well. As I have no clue, how you did that trick: Would you mind to
share the source, so that I could point them to your code to see, how
it’s done / how much work this might be?[/color]

The code is quick and dirty, but you/they are welcome to it. It’s below,
in it’s entirety, at the end of this post.
[color=blue]

One feature that might be nice would be the option to specify the
protocol as well, e.g. UDP:69, or icmpv4:8 [1 → PING][/color]

UDP I could add fairly easily, icmp would require using raw sockets
(which I’ve no idea on and no references to look at, but will see what I
can find), or possibly do-able using the icmp.dll - I’ll look into it
when I have time.
[color=blue]

But this is just an idea, not something I currently need (and,
honestly, I have no clue at all, how much work these features might be)[/color]

H.

program chkPort;
// Input: chkport-ip [timeout]
// Output: Text message + Errorlevel
// 0 if we connect,
// 1 if we timeout,
// 2 if we get a socket failure,
// 3 for an invalid address.

uses sockets,inetaux,strutils,winsock2,sysutils;
var
ConSock : LongInt;
sAddr : TInetSockAddr;
timeout : dword;
result : boolean;

procedure setnonblockingsocket( s : integer );
var
nb : dword;
begin
nb := 1; // 1 = nonblocking, 0 = blocking
winsock2.ioctlsocket( s , FIONBIO , @nb );
end;

function is_writable_socket( sck : integer; timeout : dword ) : boolean;
var
fds : tfdset;
tv : timeval;
result : boolean;
begin
fd_zero( fds );
fd_set( sck , fds );
tv.tv_sec := timeout div 1000;
tv.tv_usec := timeout mod 1000;

// select (socket+1 , read , write , except , timeout) - wait
// “timeout” to see if data can be written to “socket” without
// blocking

result := select( sck + 1 , nil , @fds , nil , @tv ) > 0;
is_writable_socket := result;
end;

begin
// create a socket, die if we fail
ConSock := Socket(af_inet, sock_stream, 0);
if ConSock = -1 then begin
writeln('Could not open socket: ');
halt(2);
end
else begin

// make it non-blocking
SetNonBlockingSocket(ConSock);

// if timeout defined use it, otherwise default to 2 secs
If paramcount >= 3 then Timeout := numb2dec(paramstr(3),10)
else timeout := 2000;

// fill in the socket info - protocol, address, port
with sAddr do begin
Family := af_inet;
Port := htons(numb2dec(paramstr(2),10));
Addr := StrToAddr(paramstr(1));
end;

// die if we can’t turn the address into something useable
If saddr.Addr = 0 then begin
writeln('Could not resolve ',paramstr(1));
halt(3);
end;

// otherwise try to connect
Result := (fpConnect(ConSock, @sAddr, sizeof(sAddr)) = 0);

// and see if it become writeable in the time allowed
result := result or is_writable_socket(consock, timeout);

// close the socket
Shutdown(ConSock, 2);

// and report results
If result then writeln(‘Port listening’)
else begin
Writeln(‘Port not listening’);
halt(1);
end;
end;
end.

Microsoft

portqry.exe

rgds

On 27/11/12 10:58, Rudolf Thilo wrote:[color=blue]

Hi.

For scripting purposes (using autoit, to check the host up/ down and
port open/closed status for TCP ports, 3389 e.g.) I’m looking for a
command line tool, similar to nmap, but it should offer the following
options:

  • Exit Code represents the scan result,
    e.g. Exit code 0=up and port is open, 1=up + closed, 3=host down

  • full functionality in ONE SINGLE EXE file (nmap needs a bunch of
    files and pcap)

the 2nd one is the more important one, if I can pipe the output to a
file and analyse that one later (like possible for NMAP) it’s fine.

The reason is, that all tools using the Win Net APIs seem to always
wait, until a timeout occurres after several seconds, no matter, what’s
the timeout setting of that tool was set, e.g. 50ms.

Any suggestions appreciated, regards, Rudi.
[/color]

On 1/4/2013 4:48 AM, mf_ncc wrote:[color=blue]

Microsoft

portqry.exe

rgds[/color]

It has the same issue as the other tools - it waits on the windows
timeout - Rudi’s requirements are for a non-blocking connect attempt
that can be timed out on a user definable basis.

H.