Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
cross referencing

Posted by matt (matt), 18 May 2003
Graham

I am having some problems with, what I thought would be a simple script. I have a two tables that I need to cross reference.

In table A I need to take an IP address at $parts[2] and then take a reference number at $parts[5].

I then need to take the reference number from table A ($parts[5]) and compare it against $parts[ 4]  in another table i.e. table B and if it matches print out $parts[3] and $parts[ 2] of table B.

I have tried numerous solutions and I am now both really confused and really fustrated, please HELP?

Matt

Posted by admin (Graham Ellis), 19 May 2003
Oh ... I'm bleary-eyed this morning ... let's see if I've understood the question ...   you have a file

Code:
xxxxxxx     yyyyyyyy   192.168.200.193   333y333   4444y44   london etc
xxxxxxx     yyyyyyyy   192.168.200.194   3ytr333   44y4444   melksham etc
xxxxytr     yyyytryy   192.148.200.195   333ytr3   4444444   devizes etc
xxxxxxx     yyyyyyyy   192.168.200.143   3333333   4444444   hull etc
xxxxxxx     yyyyyytr   192.178.230.193   3333333   4444444   swindon etc
xxxxxxx     yyytryyy   12.198.200.93   33ytr33   4444444   bath etc


and another file

Code:
0000000   1111111   Fred  Smith  melksham  wiltshire
another line Arthur Dent london londonshire
yet more Doris Day hartlepool tyneandwear
for example Boris Morrison hull humberside


and you want results like

Code:
[localhost:~/may03] graham% perl matt
IP address of interest: 192.168.200.143
Have IP in xxxxxxx yyyyyyyy 192.168.200.143 3333333 4444444 hull etc
Which is Boris Morrison
[localhost:~/may03] graham% perl matt
IP address of interest: 192.178.230.193
Have IP in xxxxxxx yyyyyytr 192.178.230.193 3333333 4444444 swindon etc
Which is  
[localhost:~/may03] graham% perl matt
IP address of interest: 111.212.32.116
[localhost:~/may03] graham%


The code that did that is:

Code:
#!/usr/bin/perl

open (FH,"second");

while (<FH>) {
       my @current = split;
       $second{$current[4]} = \@current;
       }

print "IP address of interest: ";
chop ($ipwant = <STDIN>);

open (FH,"first");
while (<FH>) {
       @record = split;
       if ($ipwant eq $record[2]) {
               print "Have IP in @record\n";
               @name = @{$second{$record[5]}}[2,3];
               if (@name) {
                       print "Which is @name\n";
                       }
       }
}


Do let me know if I've answered the right question there; if I have and you would like a further description of the program, let me know.  If not ... what have I missed and I'll modify the answer.

You do need to consider both missing and duplicated match issues, which I have ignored in my program.


Posted by matt (matt), 19 May 2003
Graham

Thanks for your reply, I am sure your code would work for my situation but again I am having trouble modifying it to suit my needs.

This one has really got me confused, I have been writing numerous scripts which have worked perfectly and I thought were more difficult. Typically this one (which I thought was an easy one) has thrown me completely.

I have included some sample info (below) so you can help an idiot like me get to grips with my specific problem.

......................................................................

I have two files (examples below)

File A: Vulnerabilities

result|network|10.0.0.1|100|etc|etc
result|network|10.0.0.1|101|etc|etc
result|networkA|10.0.0.2|101|etc|etc
result|networkB|10.0.0.3|106|etc|etc

File B: Report
100|finding: blah blah blah|recommendation: blah blah
101|finding: blah blah blah|recommendation: blah blah

what I need to do is to parse the Vulnerbilities file and determine that IP address 10.0.0.1 is vulnerable to reference number 100 and 101.

I then need to look at the Report file and take the finding and recommendation for reference number 100 and 101 and print out something like

10.0.0.1 is vulnerbale to 100 and 101
100 equals
finding: blah blah blah
recommendation: blah blah
101 equals
finding: blah blah
recommendation: blah blah

10.0.0.2 is vulnerbale to 101
101 equals
finding: blah blah
recommendation: blah blah

10.0.0.3 is not vulnerable

....................................................

I know it looks like I am asking you to write my script for me, but I have really worked myself into a corner and I am struggling to get out of it.

Keep up the good work, and thanks in advance.

Matt


Posted by admin (Graham Ellis), 20 May 2003
One of those mornings where eveything is happening.   Quick piece of code, and the results of running it ...

Code:
#!/usr/bin/perl

open (FH,"report");

while (<FH>) {
       my @current = split(/\|/,$_);
       $second{$current[0]} = $_;
       }

open (FH,"vulnerabilities");

while (<FH>) {
       my @record = split(/\|/,$_);
       push @{$first{$record[2]}},$_;
       }

foreach $host (sort keys %first) {
       print "******* $host *********\n";
       @vlist = @{$first{$host}};
       foreach $prob (@vlist) {
               @cur = split(/\|/,$prob);
               if ($second{$cur[3]}) {
                       print $second{$cur[3]};
               } else {
                       print "Vulnerability $cur[3] reported but not defined\n";
               }
       }
}


Code:
[localhost:~/may03] graham% perl matt2
******* 10.0.0.1 *********
100|finding: blah blah blah|recommendation: blah more
101|finding: blah etc blah|recommendation: blah blah
******* 10.0.0.2 *********
101|finding: blah etc blah|recommendation: blah blah
******* 10.0.0.3 *********
Vulnerability 106 reported but not defined
[localhost:~/may03] graham%


Not quite the right format, but looks like it does the job otherwise; saved your data into files, changed the report lines so that I could tell them apart ...





This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho