Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'causing': 0.04; '12px;': 0.05; 'debugging': 0.07; 'socket': 0.07; '(its': 0.09; 'get.': 0.09; 'subject:()': 0.09; 'trailing': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; '"r")': 0.16; '"w")': 0.16; '(without': 0.16; 'edward': 0.16; 'guessing': 0.16; 'instead).': 0.16; 'main():': 0.16; 'manning': 0.16; 'presume': 0.16; 'stdout': 0.16; 'helvetica;': 0.16; 'prevent': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'code,': 0.22; 'input': 0.22; 'import': 0.22; '(in': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; "shouldn't": 0.24; 'why.': 0.24; 'fine': 0.24; 'helpful': 0.24; 'mon,': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'generally': 0.29; 'reporting': 0.29; 'statement': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'included': 0.31; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; 'info.': 0.31; 'occurs': 0.31; 'anyone': 0.31; 'file': 0.32; 'figure': 0.32; 'open': 0.33; 'url:python': 0.33; 'running': 0.33; 'guess': 0.33; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'doubt': 0.36; 'done': 0.36; 'url:listinfo': 0.36; 'charset:us- ascii': 0.36; 'url:org': 0.36; 'should': 0.36; 'error.': 0.37; 'skip:- 20': 0.37; 'auto;': 0.38; 'message-id:@gmail.com': 0.38; 'thank': 0.38; 'files': 0.38; 'issue': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'skip:p 20': 0.39; 'major': 0.40; 'url:mail': 0.40; 'ensure': 0.60; 'even': 0.60; 'above,': 0.60; 'is.': 0.60; 'issues,': 0.61; 'header:Message-Id:1': 0.63; 'our': 0.64; 'provide': 0.64; 'more': 0.64; 'here': 0.66; 'results': 0.69; 'jul': 0.74; '2014,': 0.84; 'difference.': 0.84; 'subject:skip:g 10': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=nM6+FsuKISC8HpN3hW5Pip0d3deY1GKkLITv15e3MZU=; b=lgd4mD8aw7OpKTZwPWJpFEcj51daeQ7F0WfjtXPG6KfI/Vek3mEP3eAihFJjZGW4Ju a+01RpMWLZxSvYLtx8WiIQ0eZ/a4Rx4JzPT34JbfPDy9DXZOoMji13CjSDbkNf3ns+39 kfIpO6ZgbovzvDwo4qiEhpxqOE2n4vE83OqIpiZzKwypKKnlbyxkH3kbntRNssbkKt4W 56m/lrgTHD7fsGzy6O5oSQuxSTdq16EMsz2aXknmLsx6lVmu8XpZ8i67DmGOIjwpii+Y D9ZtF6x/9O17GW+TJeiIfM1Bosw5bv/1t3W4X7EXDajTnqjyqRE8cLmzbsPsCIYEjzbW a+uA== X-Received: by 10.224.167.193 with SMTP id r1mr64653796qay.62.1406583933068; Mon, 28 Jul 2014 14:45:33 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_B3485474-54C8-40D4-B6C5-BCD83F1DD066" Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1971.5\)) Subject: Re: gethostbyaddr() From: Edward Manning In-Reply-To: Date: Mon, 28 Jul 2014 17:45:31 -0400 References: <52DDE47E-D858-4ACD-A5E8-04E77F5B2CA8@gmail.com> To: Chris Kaynor X-Mailer: Apple Mail (2.1971.5) Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 219 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406583936 news.xs4all.nl 2933 [2001:888:2000:d::a6]:42556 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75329 --Apple-Mail=_B3485474-54C8-40D4-B6C5-BCD83F1DD066 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Chris=20 Thank you for the info. I figure it out. But thank you again. Ed=20 > On Jul 28, 2014, at 5:42 PM, Chris Kaynor = wrote: >=20 > On Mon, Jul 28, 2014 at 2:33 PM, Edward Manning = wrote: > 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=20 > I get a error. Does anyone have an idea why. =20 >=20 > 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. > =20 > import socket > =20 > =20 > def main(): > =20 > # get file names > infileName =3D input ("What file our the IP adderss in? ") > outfileName =3D input("What file should the results go in?") > =20 > # open files > infile =3D open(infileName, "r") > outfile =3D open(outfileName, "w") >=20 > 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: > with open(infileName, "r") as infile: > # code that needs infile goes here. >=20 > 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. > =20 > =20 > =20 > #Proccess each line of the input file > =20 > for line in infile: > ipAddress =3D line.strip() >=20 > 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: >=20 > if not ipAddress: > continue >=20 > 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... > =20 > resluts =3D socket.gethostbyaddr(ipAddress) > print(resluts[0],resluts[2], end=3D"") >=20 > Note that this does not seem to be printing into outfile (its printing = to stdout instead). I presume this is for debugging purposes. > =20 > -- > https://mail.python.org/mailman/listinfo/python-list --Apple-Mail=_B3485474-54C8-40D4-B6C5-BCD83F1DD066 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Chris 

Thank you for the = info.  I figure it out. But thank you = again.

Ed 
On Jul 28, 2014, at 5:42 PM, Chris Kaynor <ckaynor@zindagigames.com> = wrote:

On Mon, Jul 28, 2014 at 2:33 PM, Edward = Manning <ejmmanning@gmail.com> wrote:
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 
I get a error. Does = anyone have an idea why.    

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.
 
import socket
 
 
def = main():
 
    # get file = names
    infileName =3D input ("What = file our the IP adderss in?  ")
    outfileName =3D input("What = file should the results go in?")
 
    # open = files
    infile =3D open(infileName, = "r")
    outfile =3D = open(outfileName, "w")

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:
with open(infileName, "r") as = infile:
    # code that needs infile goes = here.

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.
 
 
 
    #Proccess each line of the = input file
 
    for line in = infile:
        ipAddress =3D = line.strip()

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:

if not = ipAddress:
    = continue

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...
 
        resluts =3D = socket.gethostbyaddr(ipAddress)
        print(resluts[0],resluts[2], = end=3D"")

Note that this = does not seem to be printing into outfile (its printing to stdout = instead). I presume this is for debugging = purposes.
 
--
https://mail.python.org/mailman/listinfo/python-list=

<= /html>= --Apple-Mail=_B3485474-54C8-40D4-B6C5-BCD83F1DD066--