extracting ip address from raw_input
<p>I have compiled a script in python 2.6.5, The script is simply to automate my most used functions for nmap and log the output to a txt file on the desktop.
I haven't written this all myself as i am still only learning python. I found an update script for updating backtrack and used that as a template for indentation and commands and modified it and added some of my own stuff to give me what i needed. </p>

<p>The problem i'm having is with this block</p>

<blockquote>
  <p>def nmap_target():</p>
</blockquote>

<pre><code>    try:    ip = raw_input(" [&gt;] Enter ip to scan:  ")

except KeyboardInterrupt:
    print "\n [&gt;] Exiting!\n"
            sleep(1)
    sys.exit()
    print " [&gt;] Attempting targeted scan.\n"
    #print ip 
if subprocess.Popen("nmap ip &gt;&gt; //root/Desktop/Target.txt &amp;&amp; tail /root/Desktop/Target.txt",shell=True).wait() == 0:
    print "\n"
    print " [&gt;] Targeted scan completed successfully!\n"
            menu_main()

else:
    print "\n"
    print " [&gt;] Nmap scan failed.\n"
</code></pre>

<p>The idea behind it is that it asks the user to input an ip address into raw_input() and call it ip, I'm trying to then pass it to nmap using subprocess.Popen("nmap ip as can be seen above.
The problem is its just writing nmap ip rather than printing the ip address and then returning errors, It even tries to scan out of my network, every time i test it i make sure the internet cable is unplugged from my router, This causes a bug with my internet test though, so if you try running the code bellow you may need to hash out the internet_check() option in the menu_main() section if you have your internet unplugged from the router</p>

<p>I have spent 4 days on this now and its driving me mad, At first i thought i needed to convert the number to floating point so i tried that and still the same, I've tried all sorts of things and spent hours trawling the internet looking for an answer to no avail.</p>

<p>I am now convinced its not the command i'm trying that is to blame i think it is the exit statement, I have tried putting "print ip" right after the line where it says "print " [>] Attempting targeted scan.\n" and sure enough the ip address that was entered is displayed on the screen, That proved to me that raw_input() is working. As soon as i move it anywhere bellow that it fails, This suggests to me that it must be either a problem with the exit statement or maybe indentation, I'm not sure though. 
I have also tried hashing out the keyboard interrupt as well as the couple of lines bellow, i tried moving the try: and if statements around and even tried other commands instead but it just wont work aaaarrrrrgggghhhhhh</p>

<p>Would i be right in thinking that the ip is being entered into raw_input() and then the file ip that was created that holds the ip address is being destroyed before i can pass it to subprocess.Popen("nmap ip.</p>

<p>Like i mentioned i didn't write this script from scratch and this is my first project like this so i've got a lot to learn, I've been all through the python man pages and looked through all sorts of tutorials but just can't figure this out.
Any help will be much appreciated</p>

<p>i will post the full script if anyone is interested,just as soon as i can figure out how to post code properly</p>
