It's legal to port scan networks you don't own (from a US perspective), though logging in and/ or performing changes to the device are definitely not. As another person has mentioned, you will get a lot of abuse emails but there's nothing illegal about port scanning by itself.
Source: I run Shodan (http://www.shodanhq.com)