<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 28, 2014 at 2:33 PM, Edward Manning <span dir="ltr"><<a href="mailto:ejmmanning@gmail.com" target="_blank">ejmmanning@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

I wrote this code, but it seem to work fine if I only have one ip in the file. When I have more than one IP in the file </p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

I get a error. Does anyone have an idea why.    </p></div></blockquote><div class="gmail_quote"><br></div>It would be helpful to know what the error you are getting is. It is also a good idea to generally provide the Python version and OS version with your messages, as they can often make a major difference. As it is, I've made my best guess below (in bold), I've also included some other notes that may cause issues, but I doubt are causing your error.<br>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

import socket<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

<u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">def main():<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

<u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">    # get file names<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

    infileName = input ("What file our the IP adderss in?  ")<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">    outfileName = input("What file should the results go in?")<u></u><u></u></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">    # open files<u></u><u></u></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">    infile = open(infileName, "r")<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

    outfile = open(outfileName, "w")</p></div></blockquote><div><br></div><div>While this shouldn't cause the issue your reporting (without other issues going on), Its generally a better idea to use the with statement to open file, like so:</div>

<div>with open(infileName, "r") as infile:</div><div>    # code that needs infile goes here.</div><div><br></div><div>This will ensure that the file is closed when you are done with it, even if an error occurs in the code that may prevent the code from running to completion.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

<u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">    #Proccess each line of the input file<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

<u></u> <u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">    for line in infile:<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

        ipAddress = line.strip()</p></div></blockquote><div><br></div><div>I'm guessing that, when you only have one IP, you do not have a trailing new-line in the file, but when you put more than one in the file, you have a trailing new-line. You can try adding:</div>

<div><br></div><div>if not ipAddress:</div><div>    continue</div><div><br></div><div>here to ignore any empty lines (due to the line.strip() above, it will also ignore all white-space lines) you might get. This may be the cause of your error...</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">        resluts = socket.gethostbyaddr(ipAddress)<u></u><u></u></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">

        print(resluts[0],resluts[2], end="")</p></div></blockquote><div><br></div><div>Note that this does not seem to be printing into outfile (its printing to stdout instead). I presume this is for debugging purposes.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br></div></div>