much optimized way to get the ip and run the script