How to get a value from a list with a string in AppleScript? What I try to achieve is that the dialog should output the IP adres that is in the list. 

set ipList to {DNS1:"8.8.8.8", DNS2:"8.8.4.4"}
set input to "DNS1"
set output to input of ipList
display dialog output


it gives an error:
error "input of {DNS1:\"8.8.8.8\", DNS2:\"8.8.4.4\"} kan niet worden opgevraagd. " number -1728 from input of {DNS1:"8.8.8.8", DNS2:"8.8.4.4"}

If I do: 

set output to DNS1 of ipList


it works, so my guess I should do something with variable input. 

I've been googling for some time now but I can't seem to find a hint. I'm pretty sure the answer is already somewhere on here but I can't seem to find it. Sorry for that. 

UPDATE: I think I asked the question all wrong. 

Let me retry, I have a list: 

set ipList to {DNS1:"8.8.8.8", DNS2:"8.8.4.4"}


I would like to loop through the items. So have this coded with less code:

set IP_address to "8.8.8.8"
try
    set ping to do shell script ("ping -c 2 " &amp; IP_address &amp; "| head -2 | tail -1 |cut -d = -f 4")
    if ping contains "ms" then
        set Output1 to "DNS 1 UP"
    else if ping contains "timeout" then
        set Output1 to "DNS 1 DOWN"
    end if
end try
set IP_address to "8.8.4.4"
try
    set ping to do shell script ("ping -c 2 " &amp; IP_address &amp; "| head -2 | tail -1 |cut -d = -f 4")
    if ping contains "ms" then
        set Output2 to "DNS 1 UP"
    else if ping contains "timeout" then
        set Output2 to "DNS 1 DOWN"
    end if
end try

display dialog (Output1 &amp; return &amp; Output2) buttons {"OK"} default button 1 with title "Resultaat"


Again, I'm a newbie, I'm sorry
This would be my take on this:

set ipList to {"8.8.8.8", "8.8.8.6", "8.8.4.4"}
set Output1 to ""
set Output2 to ""
global Output1, Output2
repeat with i from 1 to number of items in ipList
    set this_item to item i of ipList
    my ipCheck(this_item, i)
end repeat


if Output1 is not "" or Output2 is not "" then
    display dialog (Output1 &amp; Output2) buttons {"OK"} default button 1 with title "Resultaat"
end if

on ipCheck(IP_address, i)
    try
        set ping to do shell script ("ping -c 2 " &amp; IP_address &amp; "| head -2 | tail -1 |cut -d = -f 4")
        if ping contains "ms" then
            set Output1 to Output1 &amp; return &amp; "DNS" &amp; i &amp; "  UP"
        else if ping contains "timeout" then
            set Output2 to Output2 &amp; return &amp; "DNS" &amp; i &amp; " DOWN"
        end if
    end try
end ipCheck