Hi all, I'm trying to do something fairly simple but can't figure out whats going wrong. I'm running NBTSTAT -a on a load of IP addresses - supplied from a file NBT.CSV -It's a windoze program which gives fairly verbose output - What I'm trying to get is the first 15 characters of each line with no duplicates in comma delimited form. A fairly simple text processing job I thought - I figured without me having left my brain at home today.
The code is as follows
#!c:\perl\bin\perl -w
open(NB, "nbt.csv")|| die"Cant open input file nbt.csv";
# NBT.CSV simply contains ip addresses - one per line
while(<NB>)
{undef $line;
chomp $_;
$line="$_".",";
@nbtstat = `nbtstat -a $_`;
$len=@nbtstat;
for ($j=0; $j<$len;$j++)
{$short=substr($nbtstat[$j],0,15);
chomp $short;
unless ($line=~m/$short/)
{$line=$line.",".$short;}
}
print "$line\n";
}
close(NB);
What I get is like this - first line is correct, second line is missing the ip address at the beginning - I cant figure out why?
1.1.1.1,,Host not found.
, Name ,---------------,Registered Regi,WS12345678901,USER1,MAC Address = 0
The text this is produced from is like this
C:\Perl>nbtstat -a 1.1.1.1
Host not found.
C:\Perl>nbtstat -a 1.1.1.2
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
WS12345678901 <00> UNIQUE Registered
EUROPE-AFRICA <00> GROUP Registered
ws12345678901 <20> UNIQUE Registered
WS12345678901 <03> UNIQUE Registered
USER1 <03> UNIQUE Registered
MAC Address = 00-06-C7-E6-D8-36
Any ideas or donations of money would be gratefully received. Thanks Andrew
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.