Skip to content

Commit

Permalink
feat(src): add option to preserve hostname
Browse files Browse the repository at this point in the history
wsdd now uses the lower case version of the hostname for domains and (as
before this commit) the upper case version for workgroup environments in
its default behavior. The added -p option preserves the case information
of the provided or detected hostname.

closes #16
see also #15
  • Loading branch information
christgau committed Jun 27, 2019
1 parent cbdc202 commit 8544b1e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ allowed.

Assume that the host running wsdd joined an ADS domain. This will make
wsdd report the host being a domain member. It disables workgroup
membership reporting.
membership reporting. The (provided) hostname is automatically converted
to lower case. Use the `-p` option to change this behavior.

* `-n HOSTNAME`, `--hostname HOSTNAME`

Expand All @@ -103,10 +104,11 @@ allowed.

* `-w WORKGROUP`, `--workgroup WORKGROUP`

By default wsdd reports the host is a member of a workgroup rather than a
domain (use the -d/--domain option to override this). With -w/--workgroup
the default workgroup name can be changed. The default work group name is
WORKGROUP.
By default wsdd reports the host is a member of a workgroup rather than a
domain (use the -d/--domain option to override this). With -w/--workgroup
the default workgroup name can be changed. The default work group name is
WORKGROUP. The (provided) hostname is automatically converted to upper
case. Use the `-p` option to change this behavior.

* `-t`, `--nohttp`

Expand All @@ -125,11 +127,18 @@ allowed.
This is useful in cases where the logging mechanism, like systemd on Linux,
automatically prepend a date and process name plus ID to the log message.

* `-p`, `--preserve-case`

Preserve the hostname as it is. Without this option, the hostname is
converted as follows. For workgroup environments (see `-w`) the hostname
is made upper case by default. Vice versa it is made lower case for usage
in domains (see `-d`).

* `-4`, `--ipv4only` (see below)
* `-6`, `--ipv6only`

Restrict to the given address family. If both options are specified no
addreses will be available and wsdd will exit.
Restrict to the given address family. If both options are specified no
addreses will be available and wsdd will exit.

## Example Usage

Expand Down Expand Up @@ -176,6 +185,16 @@ reliably discovered. The reason appears to be that Windows is not always able
to connect to the HTTP service for unknown reasons. As a workaround, run wsdd
with IPv4 only.

## Usage with NATs

Do not use wssd on interfaces that are affected by NAT. According to the
standard, the _ResolveMatch_ messages emitted by wsdd, contain the IP address
("transport address" in standard parlance) of the interface(s) the application
has been bound to into. When such messages are retrieved by a client (Windows
hosts, e.g.) they are unlikely to be able to connect to the provided address
which has been subject to NAT. To avoid this issue, use the `-i/--interface`
option to bind wsdd to interfaces not affected by NAT.

## Tunnel/Bridge Interface

If tunnel/bridge interfaces like those created by OpenVPN or Docker exist, they
Expand Down
12 changes: 10 additions & 2 deletions man/wsdd.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ addreses will be available and wsdd will exit.
\fB\-d \fIDOMAIN\fR, \fB\-\-domain \fIDOMAIN\fR
Assume that the host running wsdd joined an ADS domain. This will make
wsdd report the host being a domain member. It disables workgroup
membership reporting.
membership reporting. The (provided) hostname is automatically converted
to lower case. Use the `-p` option to change this behavior.
.TP
\fB\-H \fIHOPLIMIT\fR, \fB\-\-hoplimit \fIHOPLIMIT\fR
Set the hop limit for multicast packets. The default is 1 which should
Expand All @@ -40,6 +41,12 @@ Override the host name wsdd uses during discovery. By default the machine's
host name is used (look at hostname(1)). Only the host name part of a
possible FQDN will be used in the default case.
.TP
\fB\-p\fR, \fB\-\-preserve-case\fR
Preserve the hostname as it is. Without this option, the hostname is
converted as follows. For workgroup environments (see -w) the hostname
is made upper case by default. Vice versa it is made lower case for usage
in domains (see -d).
.TP
\fB\-s\fR, \fB\-\-shortlog\fR
Use a shorter logging format that only includes the level and message.
This is useful in cases where the logging mechanism, like systemd on Linux,
Expand Down Expand Up @@ -67,7 +74,8 @@ to DEBUG.
By default wsdd reports the host is a member of a workgroup rather than a
domain (use the -d/--domain option to override this). With -w/--workgroup
the default workgroup name can be changed. The default work group name is
WORKGROUP.
WORKGROUP. The (provided) hostname is automatically converted to upper
case. Use the `-p` option to change this behavior.
.SH EXAMPLE USAGE
.SS Handle traffic on eth0 and eth2 only, but only with IPv6 addresses

Expand Down
16 changes: 10 additions & 6 deletions src/wsdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,14 @@ def wsd_handle_get():
ElementTree.SubElement(host, 'wsdp:ServiceId').text = args.uuid.urn
if args.domain:
ElementTree.SubElement(host, PUB_COMPUTER).text = (
'{0}/Domain:{1}'.format(
args.hostname.upper(),
args.domain))
'{0}/Domain:{1}'.format(
args.hostname if args.preserve_case else args.hostname.lower(),
args.domain))
else:
ElementTree.SubElement(host, PUB_COMPUTER).text = (
'{0}/Workgroup:{1}'.format(
args.hostname.upper(),
args.workgroup.upper()))
'{0}/Workgroup:{1}'.format(
args.hostname if args.preserve_case else args.hostname.upper(),
args.workgroup.upper()))

return metadata

Expand Down Expand Up @@ -613,6 +613,10 @@ def parse_args():
'-s', '--shortlog',
help='log only level and message',
action='store_true')
parser.add_argument(
'-p', '--preserve-case'
help='preserve case of the provided/detected hostname',
action='store_true')

args = parser.parse_args(sys.argv[1:])

Expand Down

2 comments on commit 8544b1e

@SoLoR1
Copy link

@SoLoR1 SoLoR1 commented on 8544b1e Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma missing on line 617

@christgau
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed that in 100d5d2

Please sign in to comment.