I am not sure if this will work for every possible combination that you might have but it works for the small sample you provided:
sed "1,\$s/state/\
state/g" file | grep state > NewFile
for IPADDR in $(cat NewFile | cut -d"@" -f2|cut -d":" -f1|sort -n|uniq);do
for STATE in 2 4 ;do
LineCount=$(grep "${IPADDR}" NewFile |grep "state:: ${STATE}"| wc -l)
echo "For IP address ${IPADDR}, status:: ${STATE} lines count is ${LineCount}"
done
done | grep -v "is 0"$
you can add as many different STATE numbers you want on the for loop inside
Basically you are inserting a new line character before each occurrence of the string `state` making your big blob of data, separating in to multiple lines.