not a scheduled task. This should be handled per request or per page load.
If you want to do this per request, you can take advantage of global events -> in your case RequestEvents.Begin.Execute:
If you want to do it per page load, then you can customize/clone the PortalTemplate and do the check there or you can create a new web part and place it on your master page.
And the the IP address for checking in scenarios above would be stored directly to the user (CMS_User table) or in some custom table/custom class with a linkage to a user (recommended).