I have to develop a service similar ( but different ) to these:
whatismyipaddress.com
iplocation.net
So, how can I get the country of the users by using their ip address and without using external web services ?
Try Geo IP Location . It uses offline database. But it won't be 100% accurate.
You can use ip to country data base. you can get it from Maxmind, IP2Location, software77, Maxmind, Geolite, ip2nation. some of free and some is paid. you can buy database from here.
Well, you will always need a third party, you might need to make a dictionary for countries allocated IP ranges and check for each visit the range it belongs to. This also won't be accurate 100%, but maybe 95%. A website that gives ip ranges to begin with: https://www.countryipblocks.net/country_selection.php