Posts | Tags | Archive

Resolving Windows NetBIOS names in Linux

When accessing computers on a LAN, it's often useful to access them by name instead of IP. This is especially true when dealing with dynamic IP addresses.

In Windows, other Windows computer names are automatically resolved to an IP address. In most Linux distros however, this is not the case (by default).

To resolve Windows NetBIOS names in Linux, you'll need the winbind component of the Samba suite. Winbind allows a UNIX box to become a full member of an NT domain, giving the ability to resolve names from it.

Install winbind via your preferred package manager. For Debian and derivatives, the following should work.

1
apt-get install winbind

Now that winbind is installed, the OS must be configured to use it when looking up hostnames. Open the file /etc/nsswitch.conf and add "wins" to the end of the line starting with "hosts:".

For example, the line in my file now looks like

1
hosts: files dns wins

Save the file and reboot to start the winbindd deamon.

To test if if worked, try pinging a computer on your LAN by name. For example:

1
2
3
4
5
$ ping windows-server
PING windows-server (192.168.0.107) 56(84) bytes of data.
64 bytes from 192.168.0.107: icmp_req=1 ttl=128 time=0.268 ms
64 bytes from 192.168.0.107: icmp_req=2 ttl=128 time=0.604 ms
64 bytes from 192.168.0.107: icmp_req=3 ttl=128 time=0.607 ms

Vim: Search and replace in multiple files

As is the way with Vim, there are a ton of features, but stumbling on the combination of commands that does what you want can be a bit difficult sometimes. In this case, the objective is to perform a search and replace over some files.

This is done in two steps: loading up the files to process, then issuing a command to run on each of the files.

Load up the files to search using the args command. This command supports multiple arguments and can use bash-style path completion.

1
:args src/*.cpp src/*.hpp README.txt

Perform a replace using sed-style syntax using the argdo command. This command iterates over all the files loaded by the args command and performs a command on them. In this case, it's performing the replace operation.

1
:argdo %s/FindMe/ReplaceWithMe/gec | update

The flags used in this case are:

  • g: global search (find more than a single occurance per line)
  • e: suppress "string not found" error messages
  • c: confirm each replace

Running update after the replace operation saves any changes to the file before moving to the next one.


How to download an entire Google Site

When using Google Sites, there is currently no way to make a backup of your site, or download the site so you can host it on another server.

This command uses a tool called wget to spider through a website and download all the public files to the local computer. Unix users will most likely have the wget tool already installed (if not, you can install it via your preferred package manager), while Windows users can get it from here.

Once wget is installed, run it with the following parameters:

1
2
3
#Downloads all public pages on a Google Site

wget -e robots=off -m -k -K -E -rH -Dsites.google.com http://sites.google.com/a/domain/site/

This tells wget to spider through all the links on your site and download the html files and linked content (such as images). Note that pages that aren't linked from anywhere on the site won't be downloaded.

This technique will also work for websites other than the ones hosted on Google Sites.

© Carey Metcalfe. Built using Pelican. Theme is subtle by Carey Metcalfe. Based on svbhack by Giulio Fidente.