Sounds like something you’d do using the Windows firewall (you can block the SQL Server port(s), and allow exceptions for certain IP addresses).
You could do this with something like a logon trigger that checked the IP address using sys.dm_exec_connections but I think it’s a much less desirable option than blocking the traffic outright.
Certainly much tougher to do at the database level.