473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parsing output of `nbtstat -a`

I have been given a text file that contains 'nbtstat -a' output for various computers in our network. The script needs extract the name of the computer and if there is a user name that nbtstat reads; extract that as well. If there is no user name then the script needs to say something like 'no user found'. does anyone have an idea how i would do that?
Aug 1 '07 #1
11 5242
numberwhun
3,509 Expert Mod 2GB
First, I have never heard of nbstat and would not have the foggiest clue as to what the format of the output is. Could you possibly provide a sample of the data so we can see it?

Also, we will be happy to help you, but must first see what you have tried thus far. Please post the code that you have tried and we will assist you from there.

Regards,

Jeff
Aug 1 '07 #2
Here is a sample of the output

Expand|Select|Wrap|Line Numbers
  1. C:\WINDOWS\system32>nbtstat -a BOB#######
  2.  
  3. Local Area Connection:
  4. Node IpAddress: [] Scope Id: []
  5.  
  6. NetBIOS Remote Machine Name Table
  7.  
  8. Name Type Status
  9. ---------------------------------------------
  10. BOB####### <00> UNIQUE Registered
  11. NT <00> GROUP Registered
  12. BOB####### <03> UNIQUE Registered
  13. BOB####### <20> UNIQUE Registered
  14. TOM_LK <03> UNIQUE Registered
  15.  
  16. MAC Address =
  17.  
I had to change the computer name and user name b/c of work. But the scipt has to read this out put and print to a file the computer name and the username associated with the computer if it has one. So far the code I have written will print the line which contains computer name. Here is what I got so far

Expand|Select|Wrap|Line Numbers
  1. #! C:\Perl\bin\perl
  2.  
  3. $data_file = "nbtstat-output.txt";
  4. open(DAT, $data_file) || die("Could not open file!");
  5. @raw_data = <DAT>;
  6. close(DAT);
  7.  
  8. @barcode = grep(m/\b\w{2,5}\d{6,9}\b/, @raw_data);
  9.  
  10. foreach $barcode(@barcode) {
  11.     print "$barcode\n";
  12. }
  13.  
This is my first time writing in perl. I am doing this project on the side to learn the language. So any help will be apprciated.
Aug 2 '07 #3
numberwhun
3,509 Expert Mod 2GB
Well, we can certainly help you, that is what we are here for. Thank you for providing the output as that helped me to understand the data's structure. I fully understand changing the data, work is work and there will always be information we have to safeguard.

As for your script, I can assume from your code you are only wanting to output the lines that list the Name/Type/Status. So, what about the following:

Expand|Select|Wrap|Line Numbers
  1. #! C:\Perl\bin\perl
  2.  
  3. $data_file = "nbtstat-output.txt";
  4. open(DAT, $data_file) || die("Could not open file!");
  5. @raw_data = <DAT>;
  6. close(DAT);
  7.  
  8. foreach $line (@raw_data)
  9. {
  10.     if ($line =~ m/\w+\s+\<\d{2}\>\s+\w+\s+\w+/)
  11.     {
  12.         print("$line");
  13.     }
  14. }
  15.  
I tested this on the data you provided, with the # signs removed and it matched the following lines:

BOB####### <00> UNIQUE Registered
NT <00> GROUP Registered
BOB####### <03> UNIQUE Registered
BOB####### <20> UNIQUE Registered
TOM_LK <03> UNIQUE Registered

Is that the result you wanted?

Also, when putting code into your postings, be sure to add the CODE tags around your script so the moderator(s) won't have to follow up behind you and do it. You will see examples of how to do this in the forum editor, off to the right the next time you post.

As for learning Perl, good choice of languages. Its awesome. Be sure to get a copy of Learning Perl as it is one of the best books IMHO. Also, be sure to read perldoc.perl.org.

Regards,

Jeff
Aug 2 '07 #4
KevinADC
4,059 Expert 2GB
did you want all the lines between "Name Type Status" and "MAC Address = "?
Aug 2 '07 #5
numberwhun
3,509 Expert Mod 2GB
did you want all the lines between "Name Type Status" and "MAC Address = "?
That is what is sounded like to me. I tested the code I put up and it does just that. :-) Let's see what he comes back with.

Regards,

Jeff
Aug 2 '07 #6
KevinADC
4,059 Expert 2GB
Well, I am confused because the OP posted this:

@barcode = grep(m/\b\w{2,5}\d{6,9}\b/, @raw_data);


but there are no places where there are six to nine digits in the lines he posted unless they are the ###### stuff we can't see.
Aug 2 '07 #7
Well, we can certainly help you, that is what we are here for. Thank you for providing the output as that helped me to understand the data's structure. I fully understand changing the data, work is work and there will always be information we have to safeguard.

As for your script, I can assume from your code you are only wanting to output the lines that list the Name/Type/Status. So, what about the following:

Expand|Select|Wrap|Line Numbers
  1. #! C:\Perl\bin\perl
  2.  
  3. $data_file = "nbtstat-output.txt";
  4. open(DAT, $data_file) || die("Could not open file!");
  5. @raw_data = <DAT>;
  6. close(DAT);
  7.  
  8. foreach $line (@raw_data)
  9. {
  10.     if ($line =~ m/\w+\s+\<\d{2}\>\s+\w+\s+\w+/)
  11.     {
  12.         print("$line");
  13.     }
  14. }
  15.  
I tested this on the data you provided, with the # signs removed and it matched the following lines:

BOB####### <00> UNIQUE Registered
NT <00> GROUP Registered
BOB####### <03> UNIQUE Registered
BOB####### <20> UNIQUE Registered
TOM_LK <03> UNIQUE Registered

Is that the result you wanted?

Also, when putting code into your postings, be sure to add the CODE tags around your script so the moderator(s) won't have to follow up behind you and do it. You will see examples of how to do this in the forum editor, off to the right the next time you post.

As for learning Perl, good choice of languages. Its awesome. Be sure to get a copy of Learning Perl as it is one of the best books IMHO. Also, be sure to read perldoc.perl.org.

Regards,

Jeff
I bought Programming Perl, it has helped somewhat but at there is just alot of information there. I also visit cpan.org as well. as far as the output I am look for,
the people who I am writing the script for want something like this
BOB####### |---tab deliminated--| Tom_LK
computer name user name

they want to eventually import this output into excel to see which users are accessing these machines.
Aug 2 '07 #8
numberwhun
3,509 Expert Mod 2GB
I bought Programming Perl, it has helped somewhat but at there is just alot of information there. I also visit cpan.org as well. as far as the output I am look for,
the people who I am writing the script for want something like this
BOB####### |---tab deliminated--| Tom_LK
computer name user name

they want to eventually import this output into excel to see which users are accessing these machines.
Programming Perl is a good reference. They call it the bible, I call it a function reference. I typically stick to Learning Perl as it does a lot more in the way of explaining things. CPAN contains all the modules and some documentation, but definitely visit perldoc.perl.org as it is filled with tons of information.

As for your issue, I am now even more confused. The output you are looking for:

BOB####### |---tab deliminated--| Tom_LK

looks to contain data from two seperate lines in your output. Is this correct? If so, we need to be able to determine what is a machine name and what is a user name. Can you describe the file further?

Regards,

Jeff
Aug 2 '07 #9
Programming Perl is a good reference. They call it the bible, I call it a function reference. I typically stick to Learning Perl as it does a lot more in the way of explaining things. CPAN contains all the modules and some documentation, but definitely visit perldoc.perl.org as it is filled with tons of information.

As for your issue, I am now even more confused. The output you are looking for:

BOB####### |---tab deliminated--| Tom_LK

looks to contain data from two seperate lines in your output. Is this correct? If so, we need to be able to determine what is a machine name and what is a user name. Can you describe the file further?

Regards,

Jeff
The output is on 2 seperate lines.
BOB#### is the computer name
TOM_LK is the user name
Basically nbtstat checks the NetBIOS information on windows machine. if a user is logged on to that machine it prints that out as well. Someone took that nbtstat information for a number of machines and redirected the output to a text file. I am not sure if they realized all the extra information they will get along with the computer and and user name; there are 2 other wrinkles. Some of the machines they ran this command against did not have a user name associated with it (basically that means that the line with TOM_LK . is not there) and there some machines the command could not find, so it printed out the phrase "host not found." Here is an idea of how all of this looks on the text file:

C:\WINDOWS\system32>nbtstat -a BOB#######

Local Area Connection:
Node IpAddress: [] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
BOB####### <00> UNIQUE Registered
DL <00> GROUP Registered
BOB####### <03> UNIQUE Registered
BOB####### <20> UNIQUE Registered
TOM_LK <03> UNIQUE Registered

MAC Address =


C:\WINDOWS\system32>nbtstat -a MOE#######

Local Area Connection:
Node IpAddress: [] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
MOE####### <00> UNIQUE Registered
DL <00> GROUP Registered
MOE####### <20> UNIQUE Registered
MOE####### <03> UNIQUE Registered

MAC Address =


C:\WINDOWS\system32>nbtstat -a BILL#######

Local Area Connection:
Node IpAddress: [] Scope Id: []

Host not found.

for the first output the script needs to printout a line like this

BOB####### TOM_LK

for the other 2 outputs the scripts needs to print

MOE####### No user found
BILL####### No user found

I hope that helps.
Aug 2 '07 #10
numberwhun
3,509 Expert Mod 2GB
The output is on 2 seperate lines.
BOB#### is the computer name
TOM_LK is the user name
Basically nbtstat checks the NetBIOS information on windows machine. if a user is logged on to that machine it prints that out as well. Someone took that nbtstat information for a number of machines and redirected the output to a text file. I am not sure if they realized all the extra information they will get along with the computer and and user name; there are 2 other wrinkles. Some of the machines they ran this command against did not have a user name associated with it (basically that means that the line with TOM_LK . is not there) and there some machines the command could not find, so it printed out the phrase "host not found." Here is an idea of how all of this looks on the text file:

C:\WINDOWS\system32>nbtstat -a BOB#######

Local Area Connection:
Node IpAddress: [] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
BOB####### <00> UNIQUE Registered
DL <00> GROUP Registered
BOB####### <03> UNIQUE Registered
BOB####### <20> UNIQUE Registered
TOM_LK <03> UNIQUE Registered

MAC Address =


C:\WINDOWS\system32>nbtstat -a MOE#######

Local Area Connection:
Node IpAddress: [] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
MOE####### <00> UNIQUE Registered
DL <00> GROUP Registered
MOE####### <20> UNIQUE Registered
MOE####### <03> UNIQUE Registered

MAC Address =


C:\WINDOWS\system32>nbtstat -a BILL#######

Local Area Connection:
Node IpAddress: [] Scope Id: []

Host not found.

for the first output the script needs to printout a line like this

BOB####### TOM_LK

for the other 2 outputs the scripts needs to print

MOE####### No user found
BILL####### No user found

I hope that helps.

Ok, one thing we really need to know. Are the ####### representative of numbers? If so, are they the same number of numbers each time? (ie: a string of 7 digits)

Regards,

Jeff
Aug 2 '07 #11
Ok, one thing we really need to know. Are the ####### representative of numbers? If so, are they the same number of numbers each time? (ie: a string of 7 digits)

Regards,

Jeff
they are a string of 7 or 9 digits. Mostly 7 but we do have some PCs wth 9 digits. each PC name is unique; this is rg string i used /\s\b\w{2,5}\d{7,9}\b/
w(2,5} = name of the PC (name letters range between 2-5 letters) the names are associated /w departments so there are a few MOE,'s BILL's etc..
d{7,9} = unique number either 7 or 9 digits long.
Aug 2 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fraser Gordon | last post by:
Hello, Hopefully someone can help me out with this issue... I have a python script that needs to run a shell command and be able to react to output from that command as it occurs (as opposed...
8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
0
by: burn_hall | last post by:
Hi, I have a problem and can't figure it out and need your help, please look at the following code and the output also a xml file snippet is down there too. Looking at the output I don't know why...
3
by: siddharth jain | last post by:
hello I want to write a little console application to get the NetBIOS names of a remote machine...exactly like the command nbtstat -a , but in a programmatic way. I googled around quite a bit...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
0
xxoulmate
by: xxoulmate | last post by:
how to extract username of computer using nbtstat., in dos mode i use nbtstat -a computername then it list down all the workgroup,the computername,and the username was there but the problem., is...
0
by: =?Utf-8?B?VWxmIFRob3JzZW4=?= | last post by:
I use Visual Studio 2005 for a C-project using an external compiler, and came up with the idea that error parsing would be neat, i.e. enabling the functionality available for a "normal" build...
1
by: avpkills2002 | last post by:
I seem to be getting this weird problem in Internet explorer. I have written a code for parsing a XML file and displaying the output. The code works perfectly fine with ffx(Firefox).However is not...
10
by: len | last post by:
I have created the following program to read a text file which happens to be a cobol filed definition. The program then outputs to a file what is essentially a file which is a list definition...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.