Skip to content

Instantly share code, notes, and snippets.

@donaldsteele
Created January 2, 2018 06:12
Show Gist options
  • Save donaldsteele/2d92eb5da9aa0fe811f4ce49d4a085a8 to your computer and use it in GitHub Desktop.
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
<?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);
?>
@sebma
Copy link

sebma commented Apr 2, 2020

@danaldsteele Thanks for the nmap command :) 👍

BTW : You can use ... | grep -Po '(\d{1,3}\.){3}\d{1,3}' for the last grep call in your first exec( call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment