#!/bin/bash

# NAME
#       smb-vnc - connect vncviewer to a PC identified by SMB-name
#
# SYNOPSIS
#       smb-vnc [smbname]
#
# DESCRIPTION
#       smb-vnc uses SMB to find the IP-adresse of the host and then connects
#       to the host using vncviewer. If smbname is not given smb-vnc uses 
#       $SMBVNC
#
# VARIABLES
#       SMBVNC - SMB name of the host.
#
# AUTHOR
#       Ole Tange http://ole.tange.dk
#       Version: 2003-MAY-19
#
# SEE ALSO
#       vncviewer(1), smbclient(1)

# Start VNC-viewer to the host with the SMB name SMBNAME
# Defaults to the enviroment variable $SMBVNC


SMBNAME=${1:-$SMBVNC}

smbclient -d=2 -L $SMBNAME -N 2>&1 | perl -ne '/Got a positive .* (172.16.\d+.\d+) / and print $1' >>/tmp/smb-ipnumre
vncviewer `smbclient -d=2 -L $SMBNAME -N 2>&1 | perl -ne '/Got a positive .* (172.16.\d+.\d+) / and print $1 and exit'`
