I'm trying to replace an IP text string with an icon by resolving the country code, it needs to be quick as there is a good few to do so does anyone know what functions I use for this?
Announcement
Collapse
No announcement yet.
Resolve IP to get ISO 3166 Country code
Collapse
X
-
Originally posted by Shrek View PostI'm trying to replace an IP text string with an icon by resolving the country code, it needs to be quick as there is a good few to do so does anyone know what functions I use for this?
but getting the country code means you have to deal with a service that has a upto date IP table for each country a few also let you have the older DB to host your own but there out of date from what I saw in the past.
-
Originally posted by Shrek View PostCheers mate, I can log previous resolves in a table to save time and time out requests and use a blank icon but I figured there may be a Microsoft function for this that would save on the AMS http?
Comment
-
Thanks, so I found a free csv of country codes and it resembles this:
Code:"1.0.0.0","1.0.0.255","16777216","16777471","AU","Australia" "1.0.1.0","1.0.3.255","16777472","16778239","CN","China" "1.0.4.0","1.0.7.255","16778240","16779263","AU","Australia" "1.0.8.0","1.0.15.255","16779264","16781311","CN","China" "1.0.16.0","1.0.31.255","16781312","16785407","JP","Japan" "1.0.32.0","1.0.63.255","16785408","16793599","CN","China" "1.0.64.0","1.0.127.255","16793600","16809983","JP","Japan" "1.0.128.0","1.0.255.255","16809984","16842751","TH","Thailand"
The thing is quite big at 6.1MB but I'm thinking converted to a MemoryEx LH file it will comfortably be under 1MB.
Comment
-
OK so I got it working online with this and LuLanes so it's responsive but the online check is limited to 1000 checks per day so I would like to use the CSV first then if that fails check online, they give you some code here:
Code:address = '174.36.207.186' ( o1, o2, o3, o4 ) = address.split('.') integer_ip = ( 16777216 * o1 ) + ( 65536 * o2 ) + ( 256 * o3 ) + o4
Comment
-
Originally posted by Shrek View PostOK so I got it working online with this and LuLanes so it's responsive but the online check is limited to 1000 checks per day so I would like to use the CSV first then if that fails check online, they give you some code here:
Code:address = '174.36.207.186' ( o1, o2, o3, o4 ) = address.split('.') integer_ip = ( 16777216 * o1 ) + ( 65536 * o2 ) + ( 256 * o3 ) + o4
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
and I don't think I have the source for it but I know its about as a plugin somwhere
Comment
-
Hi
first of all , there is no algorithm to convert an ip to country
you sould use a databse to check country ,some organizations share this kind of databases for free , and usually in csv format
here is one of them , commonly used by developers
if you open that CSV file you will see a block of data in each line
Code:"16777216","17367039","AU","AUS","AUSTRALIA"
to convert an IP to decimal value there is a simple calculation
Code:IPNo = 16777216*ip_part_1 + 65536*ip_part_2 + 256*ip_part_3 + ip_part_4
each line of CSV file against this decimal value to find whether IPNo between range of a country
for example
Code:from = 16777216 to = 17367039 if(IPNo >= tonumber(from) and IPNo <= tonumber(to)) then -- found it end
Note : you must download ip-country database from the link above and put ip-to-country.csv to AutoPlay\Docs folder
you can also convert this file to a database , but Lua's io functions are fast enough to process CSV file line by lineAttached Files
Comment
-
So I'm trying to speed this up a little and make it a bit smaller, changing the csv to look like this:
Code:"16777216","17367039","AU" "17367040","17432575","MY" "17432576","17498111","AU" "17498112","17563647","KR"
What I've done now is use the io.open method to put the csv into a table and then comparing the key with the start position gives an almost instant result from a for loop but somethings odd about the memory the app uses, prior to io.open the application uses 3.6MB of computer RAM then doing the io.open to put things in a table it goes to 34.0MB then with a collectgarbage() it drops to 28.8MB so how can it consume around 25MB of memory for a table from a file that is only 3.4MB?
Comment
-
My plugin WAS on here http://software77.net/geoip-software.htm but seems its no longer there, it downloaded there CSV that did take a little while but once you have it it works fast, then it showed the country, they had ip range, country code and then the written name of country at the time so was kinda easy at the time to do
Comment
Comment