Created
January 2, 2018 06:12
-
-
Save donaldsteele/2d92eb5da9aa0fe811f4ce49d4a085a8 to your computer and use it in GitHub Desktop.
use php and nmap to find all chromecast devices on a network quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//get default gatwway | |
exec("route -n | awk '{print $2}' | grep -v '0.0.0.0' | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'",$gw); | |
//nmap scan to get all devices with open port 8008 whis is what chromecast listens on | |
exec("nmap ".$gw[0]."/24 -p 8008 -oG - | grep 8008/open | awk '{print $2}'",$chromecasts); | |
$out=array(); | |
//loop through and get the setup info page data | |
foreach($chromecasts as $chromecast) { | |
$url='http://'.trim($chromecast).':8008/setup/eureka_info'; | |
$curl_handle=curl_init(); | |
curl_setopt($curl_handle, CURLOPT_URL,$url); | |
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); | |
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name'); | |
$query = curl_exec($curl_handle); | |
curl_close($curl_handle); | |
$data = json_decode($query,true); | |
$out[$chromecast]['data']=$data; | |
} | |
print_r($out); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@danaldsteele Thanks for the
nmap
command :) 👍BTW : You can use
... | grep -Po '(\d{1,3}\.){3}\d{1,3}'
for the lastgrep
call in your firstexec(
call.