Results 1 to 10 of 13

Thread: String output for system()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts

    String output for system()

    Hi, i've changed the system() function to return a string of executed command instead of an builtin true/false. This allows to do some interesting stuff like executing external scripts in Perl/PHP etc. and get an output from them.
    Grab it: https://github.com/voron00/libcod/co...c667fb9868f82a
    Here is a little example:
    A geolocation script written in Perl
    PHP Code:
    # List of modules
    use strict;                     # strict keeps us from making stupid typos
    use warnings;                   # helps us find problems in code
    use diagnostics;                # good for detailed explanations about any problems in code
    use Geo::IP;                    # GeoIP is used for locating IP addresses

    my $ip $ARGV[0];

    if (!
    $ip) { die("No IP-Address has been defined"); }

    if (
    $ip =~ /^192\.168\.|^10\.|^169\.254\./) { die("Local Network"); }

    if (
    $ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
        die(
    "Invalid IP-Address: $ip");
    }
        
    my $gi Geo::IP->open("Geo/GeoLiteCity.dat"GEOIP_STANDARD);
    my $record $gi->record_by_addr($ip);
    my $geo_ip_info;
    if (!
    $record) { die("No location found for this IP-Address"); }

        if (
    $record->city) {

            
    # we know the city
            
    if ($record->region_name) {

                
    # and we know the region name
                
    if ($record->city ne $record->region_name) {

                    
    # the city and region name are different, all three are relevant.
                    
    $geo_ip_info $record->city '^7,^2 ' $record->region_name ' ^7-^2 ' $record->country_name;
                }
                else {
                    
    # the city and region name are the same.  Use city and country.
                    
    $geo_ip_info $record->city '^7,^2 ' $record->country_name;
                }
            }
            else {
                
    # Only two pieces we have are city and country.
                
    $geo_ip_info $record->city '^7,^2 ' $record->country_name;
            }
        }
        
    elsif ($record->region_name) {

            
    # don't know the city, but we know the region name and country.  close enough.
            
    $geo_ip_info $record->region_name '^7,^2 ' $record->country_name;
        }
        
    elsif ($record->country_name) {

            
    # We may not know much, but we know the country.
            
    $geo_ip_info $record->country_name;
        }
        
    elsif ($record->country_code3) {

            
    # How about a 3 letter country code?
            
    $geo_ip_info $record->country_code3;
        }
        
    elsif ($record->country_code) {

            
    # How about a 2 letter country code at least?
            
    $geo_ip_info $record->country_code;
        }
        else {
            
    # I give up.
            
    $geo_ip_info "Unknown location";
        }

    print 
    "$geo_ip_info\n"
    Which i cruly copypasted from Nanny, this would return city (in some case not), region name, and country.
    So in gsc i would run it like
    PHP Code:
    location system("perl locate.pl " self getIP()); 
    and then iprintln the result:
    Click image for larger version. 

Name:	shot0001.jpg 
Views:	131 
Size:	29.5 KB 
ID:	1008
    Ye that's right.
    Last edited by voron00; 30th December 2015 at 16:50.

  2. The Following 2 Users Say Thank You to voron00 For This Useful Post:

    kung foo man (30th December 2015),Mitch (30th December 2015)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •