Please don't post pictures of your code. Use the "Code Sample" icon in the format bar (or use the Ctrl+K keyboard shortcut).
The title of your post asks for help with a "nested if" but I don't see one in the screenshot of your code.
If all of your machine names are present in DNS, and there are corresponding PTR records for the IP addresses, then using the Resolve-DnsName cmdlet will return the name associated with the IP address.