Arduino scan ip

Can arduino scan a a network and see if it's a specific device connected(by ip or mac) using ethernet or wifi esp8266? Can you help me with a code example? Thanks!

1) yes, 2) no time, but essentially you just loop over all IP addresses and do an ping (ICMP->echo)