Summary: I have a group of CGIs that check a license at runtime. The license is based on the IP of the server and it's stored in an external file. This model has been useful for a while, but I have encountered problems reading the real IP address of the machine because (I believe) the way I read the IP address is based on the hostname. Let me elaborate.

The license string is generated doing an hexdigest of the IP addres and a predefined number. I also check that the IP address is not an internal network IP (such as 10.*.*.*) or the loopback address 127.0.0.1.

Basically the license creation is done like this:

use Sys::Hostname; use Socket; use Digest::MD5; my $hostname = hostname(); my $address = gethostbyname($hostname); my $ip = inet_ntoa($address); my $key = "1234567"; # arbitray number my $md5 = Digest::MD5->new; $md5->add($key, $ip); my $license = $md5->hexdigest;

For checking the license is just the reverse of the above.

My methodology has some problems because sometimes the /etc/hosts resolves the hostname to 127.0.0.1 or to an internal IP instead of the "real" external IP. I obviously don't want to give licenses to internal IPs or the loopback address.

I wish there was a way to know the "real" IP address that the machine has for the exterior world. Question 1: Is there a better way to read the IP address?
Question 2: Have any of you implemented a similar licensing model, what other models have you used?

P.S. I have encrypted my code so the license thing is not easy to read. Although the only way to hide the source code is by deleting it :-) (FAQ).

Pax vobiscum.
-Andrés

Update: Thanks for your comments. Yes, I am aware that there is no way to be 100% sure that the customer cannot read the code. But as I mentioned before, this protection is good enough for this specific case.

In reply to Licensing model for CGIs using IP addres by amonroy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.