On Mon, 2002-02-25 at 13:48, Ionel Mugurel Ciobica wrote:
> 
> Eu sint zero la shell programing, dar nu vreau sa fac munca de mina si
> parca nu as scrie un program in fortran ca sa ma ajute.
> Am de creiat multe fisiere de genul:
> 
>      1.0000000000000000    0.0000000000000000    0.0000000000000000
>      0.5000000000000000    0.8660254037844386    0.0000000000000000
>      0.0000000000000000    0.0000000000000000    $mj

Probabil ca ar merge si in shell daca te scremi suficient de mult. Dar
problema asta arata al naibii de tare ca una care e tipica pentru un mic
script in Perl, PHP sau Python.
Avind in vedere ca ai zis ca nu prea ai experienta cu programarea shell,
si daca nu exista vreun motiv anume care sa te _oblige_ sa folosesti
shell si nu altceva, eu zic sa incerci unul din alea de mai sus, pentru
ca oricum ar fi tot o iei de la zero.
Perl are avantajul ca e instalat cam peste tot. PHP are avantajul ca are
o sintaxa aproape de C (daca stii C). Python nu prea am folosit (dar ma
gindesc eu cu mintea mea c-o avea si el avantajele lui).

Ca punct de pornire (cred ca e aproape de ce vrei tu), mai jos am inclus
un script PHP care deschide in citire un fisier care contine adrese IP
in format longint (non-dotted), le transforma in format clasic (dotted),
le rezolva la hostname-uri, si le scrie in alt fisier.

Documentatie aici: http://www.php.net/docs.php

#!/usr/bin/php -q

<?php
$fi = "input.txt";
$fo = "output.txt";

$fip = fopen("$fi", "r");
$fop = fopen("$fo", "w");

function dotify($addr) {
    $one = floor($addr / 16777216);
    $one_diff = $addr - $one * 16777216;
    $two = floor($one_diff / 65536);
    $two_diff = $one_diff - $two * 65536;
    $thr = floor($two_diff / 256);
    $fou = $two_diff - $thr * 256;
    $dotted = $one . "." . $two . "." . $thr . "." . $fou;
    return $dotted;
}

fputs($fop, "Source addr        Source name     Dest addr       Dest
name       Port\n");

while (!feof($fip)) {
    $buf = fgets($fip, 128);
    $buf = substr($buf, 1);
    if (substr($buf, 0, 1) == " ") $buf = substr($buf, 1);
    $buf = str_replace(" | ", "\t", $buf);
    $buf = ereg_replace("\040{1,}", "\t", $buf);
    $src = strtok($buf, "\t");
    $dst = strtok("\t");
    $port = strtok("\t");
    $port = strtok("\t");
    $src = dotify($src);
    $dst = dotify($dst);
    $hsrc = gethostbyaddr($src);
    $hdst = gethostbyaddr($dst);
    $buf = $src . "\t" . $hsrc . "\t" . $dst . "\t" . $hdst . "\t" .
$port . "\n";
    fputs($fop, $buf);
}

fclose($fip);
fclose($fop);
?>

-- 
Florin Andrei

"The Illuminati are watching your computer, so you need to
use morse code to blink out your PGP messages on the numlock
key." - quote from the documentation of Tinfoil Hat Linux

---
Send e-mail to '[EMAIL PROTECTED]' with 'unsubscribe rlug' to 
unsubscribe from this list.

Raspunde prin e-mail lui