about summary refs log tree commit diff
path: root/listening.1
blob: 7989a6dca83be8f4bd4bb1775d7ef5e3b3e81a12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.Dd August 8, 2023
.Dt LISTENING 1
.Os
.Sh NAME
.Nm listening
.Nd check if a TCP server is listening
.Sh SYNOPSIS
.Nm
.Op Fl 46
.Oo Fl t Ar connect-timeout Oc
.Oo Fl w Ar wait-timeout Oc
.Op Ar host
.Ar port
.Sh DESCRIPTION
The
.Nm
utility performs a TCP scan against the given
.Ar host
.Po defaulting to localhost Pc
and
.Ar port .
.Pp
This can be used to detect if a slowly starting service is ready to
accept connections.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl 4
Force use of IPv4.
.It Fl 6
Force use of IPv6.
.It Fl t Ar connect-timeout
Wait at most
.Ar connect-timeout
seconds per connection attempt
.Po default: 0.2s, decimal fractions are allowed Pc .
.It Fl w Ar wait-timeout
Wait at most
.Ar wait-timeout
seconds total
.Po decimal fractions are allowed Pc ,
and keep trying to connecting when connection has been refused
.Po default: only try once Pc .
.El
.Sh DETAILS
.Nm
implements a TCP SYN scan (half-open scan),
which has several benefits:
.Bl -bullet
.It
As the target program does not
.Xr accept 2
the connection, there's no trace of testing.
.It
It's possible to do in unprivileged Linux userspace,
thanks to
.Dv TCP_QUICKACK
and
.Dv SO_LINGER
.Po but also Linux specific Pc .
.El
.Pp
Note that firewalls may block this kind of scan,
so for reliable results
.Nm
should be used on localhost only or within a DMZ.
.Sh EXIT STATUS
.Nm
returns one of the following status codes:
.Pp
.Bl -tag -compact -width Ds
.It 0
when the port is up
.It 1
when the port refuses connection
.It 2
when timeout was reached
.It 99
if some other error occurred
.El
.Sh SEE ALSO
.Xr nc 1 ,
.Xr nmap 1
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE
.Nm
is in the public domain.
.Pp
To the extent possible under law,
the creator of this work
has waived all copyright and related or
neighboring rights to this work.
.Pp
.Lk http://creativecommons.org/publicdomain/zero/1.0/