×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Concord/GetNamefromIP: Difference between revisions

    Content added Content deleted
    imported>DrOwl
    m (simple script that outputs the names of elements that have an IPaddress given as and argument)
    imported>mutante
    mNo edit summary
     
    (12 intermediate revisions by 4 users not shown)
    Line 1: Line 1:
    this is a nice basic script that uses oracle's sql to get the element names that have a matching IP address.
    this is a nice basic script that uses oracle's sql to get the element names that have a matching [[IP]] address.
    <code>
    # more getNamefromIP.pl
    #!/bin/perl
    use strict;
    use warnings;
    # simple script that outputs the names of elements that have an IPaddress given as and argument
    # added in a simple IP address test (NOTE this is not a full IPV4 test ie it will alow 333.x.x.x)
    # but we wont worry about that as its only querying a database and will just retuirn no values
    # if not found. usage 'getNamefromIP.pl x.x.x.x'
    my $oraUser="user name here";
    my $oraPassword="password here";
    my $oraPath="path to sqlplus command here"; # eg "/oracle/bin"
    my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress
    if ($ipAddress !~ /^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/) {die "not a valid IPAddress";}
    my $elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF
    set head off
    SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';
    exit
    EOF };
    foreach my $segment (split(/ /,$elements)) {
    next if /^$/;
    next if /rows selected\.$/;
    next if /no rows selected/;
    print "$segment\n";
    }
    </code>


    related: [[Perl]]
    *<pre># more getNamefromIP.pl
    #!/bin/perl
    use strict;
    use warnings;
    #simple script that outputs the names of elements that have an IPaddress given as and argument
    # usage 'getNamefromIP.pl x.x.x.x'


    [[Concord|Back to Concord Index]]


    my $oraUser="user name here";
    my $oraPassword="password here";
    my $oraPath="path to sqlplus command here"; # eg "/oracle/bin"
    my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress


    [[Category:Concord]]
    my %elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF
    [[Category:Computer]]
    set head off
    [[Category:English]]
    SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';
    [[Category:Perl]]
    exit
    EOF };

    foreach (%elements) {
    next if /^
    /;
    next if /rows selected.$/;
    print $_;
    }</pre>

    Latest revision as of 09:18, 10 September 2006

    this is a nice basic script that uses oracle's sql to get the element names that have a matching IP address.

    # more getNamefromIP.pl
    #!/bin/perl
    use strict;
    use warnings;
    # simple script that outputs the names of elements that have an IPaddress given as and argument
    # added in a simple IP address test (NOTE this is not a full IPV4 test ie it will alow 333.x.x.x)
    # but we wont worry about that as its only querying a database and will just retuirn no values 
    # if not found. usage 'getNamefromIP.pl x.x.x.x'
    
    
    my $oraUser="user name here";
    my $oraPassword="password here";
    my $oraPath="path to sqlplus command here"; # eg "/oracle/bin"
    my $ipAddress=$ARGV[0] || die "Missing args  $!";      # get  ipAddress
    
    if ($ipAddress !~ /^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/) {die "not a valid IPAddress";}
    my $elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF
    set head off
    SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';
    exit
    EOF };
    
    foreach my $segment (split(/ /,$elements)) {
       next if /^$/;
       next if /rows selected\.$/;
       next if /no rows selected/;
       print "$segment\n";
    }
    

    related: Perl

    Back to Concord Index

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.

    Recent changes

  • BruderSpektrum • 11 hours ago
  • BruderSpektrum • 15 hours ago
  • BruderSpektrum • 15 hours ago
  • BruderSpektrum • 15 hours ago
  • Cookies help us deliver our services. By using our services, you agree to our use of cookies.