There are multiple ways to do this, my solution uses only built-in modules.
The basic idea is that for all your proper content sites, you only use host name bindings. This way they are not accessible using an IP address.
Then you use an extra site, which you don't bind to a hostname but to all IP addresses on the server. That site handles all requests that are not picked up by any of the other web sites. On that site you redirect everything to Google.com
Here's how to do this, I'm using PowerShell commands so make sure you have that IIS-PowerShell module installed:
Enable-WindowsOptionalFeature -online -FeatureName IIS-ManagementScriptingTools
I'm using the pre-installed Default Web Site
as the catch-all site, confirm that the site is bound to all IP addresses:
ls IIS:\Sites\
you should get something like:
Name ID State Physical Path Bindings
---- -- ----- ------------- --------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
http *:80:
means port 80 on all IP addresses without a hostname.
You need the http-redirect module:
Enable-WindowsOptionalFeature -online -FeatureName IIS-HttpRedirect
Now set up the redirection for all requests to the site:
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -filter "system.webServer/httpRedirect" -name "enabled" -value "True"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -filter "system.webServer/httpRedirect" -name "destination" -value "https://www.google.com"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -filter "system.webServer/httpRedirect" -name "exactDestination" -value "True"
Now all requests to any IP addresses on the server should redirect to google.com, you can now add additional sites with bindings to hostnames.
When dealing with https, it gets a little bit more complicated, but using https with an IP address will result in a certificate error anyways.