Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0

    Thumbs down I need some help please


    I started writing Pascal when Turbo Pascal first came out (on an 8" floppy disk) - long time ago! I moved through most of the versions of TP and then Delphi and finished up on Delphi 5.

    I last programmed 'in anger' in 2006. I'm now 72 but retirement doesn't suit me and I got bored so I started to program again. I still do some consulting work for a local company and I moved up to XE3.

    It's amazing how much you forget after a 7 year break, but I've sorta got the hang of it again, but XE3 is a different beast (and it's been a while), and I need a bit of help.

    I found and downloaded Geoip.pas. After some hassles and a lot of browsing the web, I got it to compile, but here come the questions : -

    1. Is it possible to add this Unit to the 'standard units' so I can just add it to the Uses clause. If not what is the best way to make use of it in XE3? Where should I put it (no smart Alec remarks please!)
    2. Can someone tell me HOW to use it. I wrote a program that browses logfiles and picks out script kiddies efforts to hack the site. I have the IP addresses (in ACSII) but I want to look up the GeoIP details. Could someone PLEASE give me some info as to how best to do this.

    Thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    55
    Rep Power
    6
    http://stackoverflow.com/questions/14332203/can-i-make-a-custom-delphi-component-add-multiple-units-to-the-uses-clause
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0
    Thanks for nothing!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    I've worked with the free "lite" versions of the database available by GeoIP. I use the GeoLite ASN and the GeoLite City (which as best I can tell, incorporates the same information as the Geolite Country)

    You can download the *.dat files from here

    http://dev.maxmind.com/geoip/geolite

    They seem to provide updated data files at least once a month.

    As far as using it, I'm sure you downloaded the Pascal API. But you will need to modify the source file since it was written before Delphi switched to Unicode Strings, so for it to work with XE3, you'll need to alter all variables declared as string to ANSIString and all PChar to PANSIChar.

    To use the unit, the simplest solution is to have the actual GeoIP API source code in the same directory of your program's source code. Once you copy the source to your program's directory, and with your program loaded into the XE3 IDE, right click on the project group window (top right window) on your exe's name and select Add. Navigate to your program's directory if not already there, and select the source. Make the changes to the String and PChar variables as I indicated above.

    With that, you can now start coding:

    Example Code to Call GeoLite City:
    Code:
    procedure TForm1.CallGeoIPCity(IPAddress: String);
    var
      GeoIP: TGeoIP;
      GeoIPCity: TGeoIPCity;
      City: String;
      CountryCode: String;
      Region: String;
      PostalCode: String;
      CountryName: String;
      CountryCode: String;
      Lat, Long: String;
      AreaCode: String;
    begin
      GeoIP := TGeoIP.Create('<Path to your GeoLite City Data Files (to include file name & ext)>');
      try
        if GeoIP.GetCity(ANSIString(IPAddress), GeoIPCity) = GEOIP_SUCCESS then
        begin
          City := String(GeoIPCity.City);
          CountryCode := String(GeoIPCity.CountryCode);
          Region := String(GeoIPCity.Region);
          PostalCode := String(GeoIPCity.PostalCode);
          CountryName := String(GeoIPCity.CountryName);
          CountryCode := String(GeoIPCity.CountryCode);
          Lat := FloatToStr(GeoIPCity.Latitude);
          Long := FloatToStr(GeoIPCity.Longitude);
          AreaCode := IntToStr(GeoIPCity.AreaCode);
        end;
      finally
        GeoIP.Free;
      end;
    end;
    To code GeoLite ASN (Organizational Data)
    Code:
    procedure TForm1.CallGeoASN(IPAddress: String);
    var
      GeoIP: TGeoIP;
      GeoIPOrganization: TGeoIPOrg;
      OrganizationName: String;
    begin
      GeoIP := TGeoIP.Create('<Path to your GeoLite ASN Data File (to include file name & ext')'>);
      try
        if GeoIP.GetOrg(ANSIstring(IPAddress), GeoIPOrganization) = GEOIP_SUCCESS then
          OrganizationName := String(GeoIPOrganization.OrgName);
      finally
        GeoIP.Free;
      end;
    end;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0

    Smile


    FANTASTIC! That is really useful. Thanks a stack. I'll give it a bash and if I get stuck, I'll come back. A lot of my Delphi knowledge has vanished in the rivers of time they say "If you don't use it - You lose it" I've just proved how true that is!!!

    Originally Posted by majlumbo
    I've worked with the free "lite" versions of the database available by GeoIP. I use the GeoLite ASN and the GeoLite City (which as best I can tell, incorporates the same information as the Geolite Country)

    You can download the *.dat files from here

    http://dev.maxmind.com/geoip/geolite

    They seem to provide updated data files at least once a month.

    As far as using it, I'm sure you downloaded the Pascal API. But you will need to modify the source file since it was written before Delphi switched to Unicode Strings, so for it to work with XE3, you'll need to alter all variables declared as string to ANSIString and all PChar to PANSIChar.

    To use the unit, the simplest solution is to have the actual GeoIP API source code in the same directory of your program's source code. Once you copy the source to your program's directory, and with your program loaded into the XE3 IDE, right click on the project group window (top right window) on your exe's name and select Add. Navigate to your program's directory if not already there, and select the source. Make the changes to the String and PChar variables as I indicated above.

    With that, you can now start coding:

    Example Code to Call GeoLite City:
    Code:
    procedure TForm1.CallGeoIPCity(IPAddress: String);
    var
      GeoIP: TGeoIP;
      GeoIPCity: TGeoIPCity;
      City: String;
      CountryCode: String;
      Region: String;
      PostalCode: String;
      CountryName: String;
      CountryCode: String;
      Lat, Long: String;
      AreaCode: String;
    begin
      GeoIP := TGeoIP.Create('<Path to your GeoLite City Data Files (to include file name & ext)>');
      try
        if GeoIP.GetCity(ANSIString(IPAddress), GeoIPCity) = GEOIP_SUCCESS then
        begin
          City := String(GeoIPCity.City);
          CountryCode := String(GeoIPCity.CountryCode);
          Region := String(GeoIPCity.Region);
          PostalCode := String(GeoIPCity.PostalCode);
          CountryName := String(GeoIPCity.CountryName);
          CountryCode := String(GeoIPCity.CountryCode);
          Lat := FloatToStr(GeoIPCity.Latitude);
          Long := FloatToStr(GeoIPCity.Longitude);
          AreaCode := IntToStr(GeoIPCity.AreaCode);
        end;
      finally
        GeoIP.Free;
      end;
    end;
    To code GeoLite ASN (Organizational Data)
    Code:
    procedure TForm1.CallGeoASN(IPAddress: String);
    var
      GeoIP: TGeoIP;
      GeoIPOrganization: TGeoIPOrg;
      OrganizationName: String;
    begin
      GeoIP := TGeoIP.Create('<Path to your GeoLite ASN Data File (to include file name & ext')'>);
      try
        if GeoIP.GetOrg(ANSIstring(IPAddress), GeoIPOrganization) = GEOIP_SUCCESS then
          OrganizationName := String(GeoIPOrganization.OrgName);
      finally
        GeoIP.Free;
      end;
    end;
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by Baldur2630
    FANTASTIC! That is really useful. Thanks a stack. I'll give it a bash and if I get stuck, I'll come back. A lot of my Delphi knowledge has vanished in the rivers of time they say "If you don't use it - You lose it" I've just proved how true that is!!!
    Hopefully you won't have any issues, if you do, you can post another question, but I'm heading out for my long needed vacation (it's been a long time), so I may not be able to get back to you immediately.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0
    I went to the GeoIP site and there are at least 6 different databases. Which one(s) should I download?

    Have a great vacation!

    Originally Posted by majlumbo
    Hopefully you won't have any issues, if you do, you can post another question, but I'm heading out for my long needed vacation (it's been a long time), so I may not be able to get back to you immediately.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by Baldur2630
    I went to the GeoIP site and there are at least 6 different databases. Which one(s) should I download?
    Click the links under the column Binary / gzip for both the GeoLite City (GeoLiteCity.dat) and GeoLite ASN (GeoIPASNum.dat).
    (NOT the IPv6 versions)

    Also, I forgot to mention in my first post. Remember to add the unit to the uses clause of your program. Just adding the unit to the project is not enough, it has to be in the uses clause.

    Originally Posted by Baldur2630
    Have a great vacation!
    Thanks, I intend to...
    Last edited by majlumbo; March 26th, 2013 at 02:48 PM.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0
    I think some Code might be missing

    [dcc32 Error] GetIPS.pas(50): E2003 Undeclared identifier: 'CallGeoIPCity'
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by Baldur2630
    I think some Code might be missing

    [dcc32 Error] GetIPS.pas(50): E2003 Undeclared identifier: 'CallGeoIPCity'
    CallGeoIPCity is a procedure that you have to define. You have to add it to your form's declaration...

    Code:
    Form1 = class(TForm)
    ...
    private
       procedure CallGeoIPCity(IPAddress: String);<--you need to add this line to your form's declaration.
      procedure CallGeoASN(IPAddress: String);<--and this one
    public
       ..
    end;
    Once you do this, on your keyboard click Control-Shift-C. That will add the stub methods to your source code, you just need to add the code I gave you to those stubs.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0
    TWO Errors : -

    1. CountryCode Declared twice (fixed)
    2. OrganizationName := String(GeoIPOrganization.OrgName);
    With message [dcc32 Error] GetIPS.pas(97): E2003 Undeclared identifier: 'OrgName'

    I could remove this line, but Organization name is one of the important things that I want to get
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by Baldur2630
    2. OrganizationName := String(GeoIPOrganization.OrgName);
    With message [dcc32 Error] GetIPS.pas(97): E2003 Undeclared identifier: 'OrgName'
    If you type

    GeoIPOrganization
    then hit the period "." and stop
    Delphi will pop up with all the methods you can call from the unit.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0
    Yes, I eventually found it and I've managed to get the whole program working. At the moment, I output the data as a CSV file that I can read into Excel. Eventually I want to put it into a database, but I still trying to find a way to connect to a MySQL server on a CentOS box without having to fork out 200 Euros of my pension for Microlap DAC for MySQL. I had this (v2.2) on Delphi 5, but it's very much out of date.

    Anyway, thanks for all the help. I have NO doubt that I'll be back!
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by Baldur2630
    Yes, I eventually found it and I've managed to get the whole program working. At the moment, I output the data as a CSV file that I can read into Excel. Eventually I want to put it into a database, but I still trying to find a way to connect to a MySQL server on a CentOS box without having to fork out 200 Euros of my pension for Microlap DAC for MySQL. I had this (v2.2) on Delphi 5, but it's very much out of date.

    Anyway, thanks for all the help. I have NO doubt that I'll be back!
    To connect to MySQL, I suggest you look at the Zeos components. They are free.. You can check them out here.
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    Belgium
    Posts
    15
    Rep Power
    0
    This is SO frustrating. I have the same problem as I had when I tried to get Lazarus to work. I installed the Zeoslib. All the components are there, libmysql is in the Windows\System and the SysWOW64. I configured the component to point to the libmysql file, but no connection

    I've got about every version of libmysql known to man, but it always comes up with the error message that it can't find the libysql.dll. That was the great thing about the Microolap component IT JUST WORKED!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo