I have to determine in a repetitive and fast way if different connection still exist.
My input is a list of IP-Adresses and my output should look like this:
IP-Adress | Connection | Response time |
1.2.3.4 | found | 20ms |
4.5.6.7 | found | 25ms |
8.9.10.11 | not found | null |
Response time would be nice, but is not urgent. My idea was to write a list of cmd ping commands to a .bat file and to run this by command line tool. But I don´t know for example how to handle an error. I appreciate any suggestions.
Solved! Go to Solution.
Hi @CaptainJaneway, I was able to do something similar using a powershell script with Alteryx. My powershell script is below, which I saved to my desktop. I then used a Run Command tool to bring the data back into my workflow. Below is a picture of how I configured it. I basically used two CSV files- one with all my IP addresses that I wanted to look up saved to it, and one that powershell wrote to. You can see them both referenced in the code below. I hope this helps!
$myArray = get-content -path 'C:\users\JoBen\Desktop\IPAddressList.csv'
foreach ($element in $myarray) {
$ip=[IPAddress] $element
if (Test-Connection $ip -Quiet -Count 1) {
#Writes successful connection IP Address and Response Time
Test-Connection $ip | Select-Object Address,ResponseTime | export-CSV -append -force -path C:\Users\JoBen\Desktop\Output.csv
} else {
# Writes the IP Address that failed
Add-Content -force -path C:\Users\JoBen\Desktop\Output.csv -Value "$ip, Invalid_IP_Address"
}
}
Thank you so much. This solution works very well. If I want use hostnames instead of IPs to check the connection, then I have to use $hostname as variable?
Okay. You bet. The name of the variable shouldn't matter, but you will need to change the script some to work with host names instead. Try this below to see if it works for you.
$myArray = get-content -path 'C:\users\JoBen\Desktop\IPAddressList.csv'
foreach ($element in $myarray) {
if (Test-Connection -ComputerName $element -Quiet -Count 1) {
#Writes successful connection IP Address and Response Time
Test-Connection $element | Select-Object Address,ResponseTime | export-CSV -append -force -path C:\Users\JoBen\Desktop\Output.csv
} else {
# Writes the IP Address that failed
Add-Content -force -path C:\Users\JoBen\Desktop\Output.csv -Value "$element, Invalid_IP_Address"
}
}