?
Solved

Script hyperterminal

Posted on 2009-04-27
9
Medium Priority
?
1,595 Views
Last Modified: 2012-05-06
Hello,

I have 40+ computers where I need to enter a unique user/password on a per-PC basis, Windows XP is the OS.

The unique identifier between each is the IMSI number which I can get by issuing the command to hyperterminal pointed at the COM port.

The deal is that I want it to do this automatically.
I've broken it into 3 parts:
- Obtain IMSI number (Hyperterminal)
- Compare it to an array/list over IMSI numbers with USER/PW
- Write the output(user/pw) to file(XML) in designated location


I've written scripts before in both PERL and VBscript so example codes for these are just fine.

If it ends up being in PERL, I need to get a way to compile it to an EXE because I am unable to install PERL to the computers that will end up having this automation.
0
Comment
Question by:TheFlyingCorpse
  • 5
  • 4
9 Comments
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 2000 total points
ID: 24242875
For perl, you can access the COM ports using the Device::Modem, or Device::SerialPort, or Win32::SerialPort, all available on CPAN.

To create an exe from your perl program, you can use perl2exe, or pp:
    http://www.indigostar.com/perl2exe.htm
    http://search.cpan.org/~smueller/PAR-Packer-0.991/lib/pp.pm
0
 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24243059
Thank you for the references to the modem bits, they look valuable in part 1.

Any example code on how I can write the output based on the result of the IMSI?

Do a search and replace in the output file where USERNAME gets replaced with $USER and PASSWORD gets replaced with $PASS ? This requires setting $USER and $PASS based on the IMSI number.
I am not that very good with arrays, hehe ;)
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 24243907
>>Any example code on how I can write the output based on the result of the IMSI?
This will depend on how you want to check the contents of IMSI.

Here is an example that will read a file (template.txt), replace USERNAME with the contents of $user and PASSWORD with the contents of $pass, and write it to a file (new.txt).
my $user = 'some_user_name';
my $pass = 'some_password';
 
local $/;
open(my $in, "<template.txt") or die "Could not open template: $!\n";
my $data=<$in>;
close($in);
$data =~ s/USERNAME/$user/;
$data =~ s/PASSWORD/$pass/;
open(my $out, ">new.txt") or die "Could not open new: $!\n";
print $out $data;
close($out);

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24244418
could you comment the code a bit?


say IMSI = 12578132581290578125
this imsi has username asfd@domain.com
password: asfjk28

now if I have a file with 40 imsi's, usernames and passwords, how could I then find the proper one in this list with the right user/pw combo?


Thanks :)
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 2000 total points
ID: 24244916
What is the format of the file listing IMSI, username, and password?  Is it a CSV file?  Some other format?

Here is the code again, commented
#Define username and password.  I guess these should
#come from your file
my $user = 'some_user_name';
my $pass = 'some_password';
 
#Read entire file at once
local $/;
 
#Open file for reading, associate file handle with variable $in,
#die with error message if could not open
open(my $in, "<template.txt") or die "Could not open template: $!\n";
 
#Read file, then close
my $data=<$in>;
close($in);
 
#Replace the string "USERNAME" with what is in variable $user
#Replace the string "PASSWORD" with what is in variable $pass
$data =~ s/USERNAME/$user/;
$data =~ s/PASSWORD/$pass/;
 
#Open file for writing, creating if necessary
#associate file handle with variable $out
#die with error message if could not open
open(my $out, ">new.txt") or die "Could not open new: $!\n";
 
#Write new data to file, close file
print $out $data;
close($out);

Open in new window

0
 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24245717
the file can be whatever is most easy to use :) CSV or TXT or whatever ;-)
0
 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24245739
what I have now thanks to you is part 3, I think I'll have a go at part 1 myself, just need part 2 then, reading the file with the IMSI/usr/pw and find the proper table for it.


/R
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 2000 total points
ID: 24245791
This will read the imsi file into a hash, with the key being the imsi number, and the value an array ref of username, password.  It assumes the file is a CSV file, with the first field the imsi number, the second the username, the third the password, like so:
12578132581290578125,username1,password1
123456,username2,password2
...


##### Read file into %imsi
my %imsi;
open(my $in, "<imsi_username_password.csv") or die "Could not open imsi file: $!\n";
while(<$in>) {
    chomp;
    my @f=split/,/;
    next unless $#f==2;
    $imsi{$f[0]} = [$f[1],$f[2]];
}
close($in);
 
 
##### Get a username, password for an IMSI
my $imsi = '12578132581290578125';  #This will come from the serial port, or wherever
die "Username and Password not found for imsi $imsi\n" unless exists($imsi{$imsi});
my ($username, $password) = @{$imsi{$imsi}};
#now, $username and $password are the values from the file

Open in new window

0
 
LVL 2

Author Closing Comment

by:TheFlyingCorpse
ID: 31574875
Very fast to respond and easy to understand, top notch :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question