Ever used nbtscan by Alla Bezroutchko (a pretty good NetBIOS Scanner)??? If you did, you should have realized that copying by hand each IP address, computer name and the #PRE string into lmhosts is a hellish thing, expecially if you did scan a wide range of hosts.
This Perl script works for you, matching the right strings into nbtscan typical output and formatting them in such a way that you just need to cut and paste the whole thing into lmhosts and reload the host table. Then you'll be able to connect remote resources in a snap of your fingers.
enjoy
SiG
P.S.: this is one of my earliest scripts, and I didn't look for elegance! By the way, it works and saved me a lot of work!
#!/usr/bin/perl print ""; print " - Sigmund Baginov NetBIOS2Lmhosts -\n"; print " - The NetBIOS Scan Output Ordinator-\n"; print " -=# Version 1.0 - August 2001 #=-\n"; print " odOOOOboo __.--._\n"; print " oOOOOOOOOOOOO° °,\n"; print " OOOOOOOOOOOOOOO .-°\n"; print " OOOOOOOOOOOOOOOOO .-°\n"; print " OOOOOOOOOOOOOOL.-°\n"; print " .-° OOOOOOOOOT.I°OO\n"; print " .° °OOOL-T°OOOO° \n"; print " °-...--+°°OOOOOOP°°\n"; print "\n"; print "\n"; print "Insert Input File:\n"; $in = <STDIN>; print "Output File? (usually lmhosts)\n"; $out = <STDIN>; open (INF,"< $in"); open (OUF,"> $out"); ######################################## # Definition of strings to match ######################################## $conf = "NetBIOS Name Table for Host "; $conf2 = "<00>"; $conf3 = "UNIQUE"; ################################### # Main loop ################################### while (!eof(INF)) { $line = <INF>; ################################### # Find "NetBIOS Name...etc..." ################################### if ($line =~ /$conf+./) { $line =~ s/$conf//; $line =~ s/\x3A//; chop $line; $line = $line."\t"; print OUF $line; $control = 1; } if ($control == 1) { ########################################## # Find Computer Name ########################################## if ($line =~ /.+$conf2+.+$conf3/) { $line =~ s/$conf2//; $line =~ s/$conf3//; $line =~ s/\W//g; $line = $line."\t"."#PRE"."\n"; print OUF $line; $control = 0; } } } close(INF); close(OUF); print "\n"; print "Done. Control output editing lmhosts.\n"; print "Execute \"nbtstat -R\" to refresh\n";

Replies are listed 'Best First'.
Re: NbtScan Output Formatter
by z0d (Hermit) on Aug 06, 2001 at 23:08 UTC
    Just a few comments. They are for improving Your programs.

    1. use -w or 'use warnings;'. I consider programs buggy without it.
    2. ALWAYS check the return code of system calls (e.g. open(), opendir() etc).
    3. You could use 'use stritct;'. It is good to use.
    4. You can use here documents to print multiple lines without needing to write multiple prints.

    I hope You take these advices.
    -- <-- z0d -->