IP Restricting admin pages with whitelist in custom module
This does not.need to be done in code. I.would use https://www.drupal.org/project/restrict_by_ip  and set a role for specific IP that would have the specific  permissions that you need.