The question is more goal oriented than particular to the technologies mentioned, so I'm just going to address the problem according to my spirit. I am going to use python.
Re: issue number 1:
Basically it sounds like you want to parse ip/addresses from a file and run an expect (like) back-and-forth sequence for each ip address.
You don't want to be parsing ip addresses from an except script -- but rather you want to parse ipaddresses from file with python and run the same expect command for each ip address.
So you would need to write the expect command with the ipaddress being a variable so that for each ipaddress in your loop, you assign a different ipaddress to that variable and execute the expect command.
As for the 'expect' like functionality, take a look at the 'pexpect' library: It's a python module that exposes to your python scripts expect like functionality. (See this answer that contains an example and links to other docs/examples: https://stackoverflow.com/a/11160553/1248361). Lets flesh it out a bit:
Looking at the example in the forgoing link, note expect sequence begins with, """
child = pexpect.spawn('some command that requires a password')
You can easily replace that string argument to the pexpect.spawn method with pexpect.spawn('some command that requires a password that takes an ipaddress as an option' + ipaddress_variable)
So in python I would just define a function that takes as an argument(s) the part(s) of the expect sequence that will change in each iteration of your for loop, and write the expect sequence inside the body of the function using the variable arguments.
Like this (this is pseudo code):
pexpect.spawn('some command that requires a password' +ipaddress_variable)
child.expect..... (here is where you take over and do what you need to do on the remote machine)
(Sorry about the formatting, pre and code didn't do what I had hoped)
With that funciton defined, the rest is easy.
Simply loop through your ipaddress and call the function, like this psuedo code:
for ipaddress in ipfile:
problem number two I would also handle through python.