[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Core Python Programming . . .

FireNWater

1/18/2008 7:50:00 PM

I'm working my way thru the book "Core Python Programming" 2d Edition
- Wesley Chun. . .

Trying to figure out what he's looking for on Page 248, Exercise 6-11
(a).

Is it supposed to be:

1) convert a 4-digit Integer (WXYZ) to an IP address (WWW.XXX.YYY.ZZZ)

or

2) convert an 8-digit Integer (WWWXXXYYYZZZ) to (WWW.XXX.YYY.ZZZ)

Thanks for anyone with the clue!!!
8 Answers

Paul Rubin

1/18/2008 7:56:00 PM

0

FireNWater <khoard@gmail.com> writes:
> 1) convert a 4-digit Integer (WXYZ) to an IP address (WWW.XXX.YYY.ZZZ)
>
> or
>
> 2) convert an 8-digit Integer (WWWXXXYYYZZZ) to (WWW.XXX.YYY.ZZZ)
>
> Thanks for anyone with the clue!!!

Without being able to see the exercise I suspect it's turn a 4-byte
string (i.e. 32 bits) into an IP address (int8.int8.int8.int8).
Or, it might be turn a 32-bit int into such an address.

Mike Driscoll

1/18/2008 10:18:00 PM

0

On Jan 18, 1:55 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> FireNWater <kho...@gmail.com> writes:
> > 1) convert a 4-digit Integer (WXYZ) to an IP address (WWW.XXX.YYY.ZZZ)
>
> > or
>
> > 2) convert an 8-digit Integer (WWWXXXYYYZZZ) to (WWW.XXX.YYY.ZZZ)
>
> > Thanks for anyone with the clue!!!
>
> Without being able to see the exercise I suspect it's turn a 4-byte
> string (i.e. 32 bits) into an IP address (int8.int8.int8.int8).
> Or, it might be turn a 32-bit int into such an address.

I've got the book and I think the OP may be referring to this:

6-11 Conversion.
(a) Create a program that will convert from an integer to an
Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ
(b) Update your program to be able to do the vice verse of the
above.


It could be a 12 digit int...or it could be what you (Paul) are
referring to.

Mike

Yu-Xi Lim

1/19/2008 12:01:00 AM

0

Mike Driscoll wrote:
>
> 6-11 Conversion.
> (a) Create a program that will convert from an integer to an
> Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ
> (b) Update your program to be able to do the vice verse of the
> above.

I think it's is asking to convert a 32-bit int to the dotted form.

It's a little known fact, but IP addresses are valid in non-dotted
long-int form. Spammers commonly use this trick to disguise their IP
addresses in emails from scanners.

FireNWater

1/19/2008 1:48:00 PM

0

On Jan 18, 6:00 pm, Yu-Xi Lim <y...@ece.gatech.edu> wrote:
> Mike Driscoll wrote:
>
> > 6-11 Conversion.
> > (a) Create a program that will convert from an integer to an
> > Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ
> > (b) Update your program to be able to do the vice verse of the
> > above.
>
> I think it's is asking to convert a 32-bit int to the dotted form.
>
> It's a little known fact, but IP addresses are valid in non-dotted
> long-int form. Spammers commonly use this trick to disguise their IP
> addresses in emails from scanners.

I guess I'm not fully up to speed on what constitutes an IP address.
Does the term 'octet' refer to an 8-bit (xFF) number?

Yu-Xi Lim

1/19/2008 1:57:00 PM

0

FireNWater wrote:

> I guess I'm not fully up to speed on what constitutes an IP address.
> Does the term 'octet' refer to an 8-bit (xFF) number?

Yes, it somewhat archaic though. It's used when "byte" is ambiguous. On
some ancient (by computing standards) computers, the size of a byte may
be as small as 6 bits or as big as 9.

For the purposes of this question, I think it's safe to assume an IP
address is just a 32-bit number. And you need to extract each group of
8-bits and print those out with dots between them.

Jorgen Grahn

1/20/2008 3:00:00 PM

0

On Sat, 19 Jan 2008 08:57:24 -0500, Yu-Xi Lim <yuxi@ece.gatech.edu> wrote:
> FireNWater wrote:
>
>> I guess I'm not fully up to speed on what constitutes an IP address.
>> Does the term 'octet' refer to an 8-bit (xFF) number?
>
> Yes, it somewhat archaic though.

It's more precise than byte, like you say. I don't think its archaic
though; it's a fairly common term when you are talking data
communication in general and IP-based protocols in particular.

> It's used when "byte" is ambiguous. On
> some ancient (by computing standards) computers, the size of a byte may
> be as small as 6 bits or as big as 9.

On ancient computers and in some embedded processors. I have a Texas
Instruments DSP in my cellphone with 16-bit words. A C "char" is 16
bits in that environment.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!

wesley chun

1/23/2008 1:00:00 AM

0

> > 6-11 Conversion.
> >   (a) Create a program that will convert from an integer to an
> > Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ
> >   (b) Update your program to be able to do the vice verse of the above.
>
> I think it's is asking to convert a 32-bit int to the dotted form.
>
> It's a little known fact, but IP addresses are valid in non-dotted
> long-int form.  Spammers commonly use this trick to disguise their IP
> addresses in emails from scanners.


that is correct. don't read too much into it. i'm not trying to
validate anything or any format, use old or new technology. it is
simply to exercise your skills with numbers (specifically 32-bit/4-
byte integers), string manipulation, and bitwise operations. if you
wish to use different sizes of numbers, forms of addressing, IPv6,
etc., that's up to you. don't forget about part (b), which is to take
an IP address and turn it into a 32-bit integer.

enjoy!
-- wesley

ps. since you're on p. 248, there is also a typo in the piece of code
right above this exercise, Example 6.4, which is tied to exercise
6-7. "'fac_list'" should really be "`fac_list`", or even better,
"repr(fac_list)". see the Errata at the book's website http://core...
for more details.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://core...

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebcons...

FireNWater

1/23/2008 5:18:00 PM

0

On Jan 22, 5:00 pm, wesley chun <wes...@gmail.com> wrote:
> > > 6-11 Conversion.
> > > (a) Create a program that will convert from an integer to an
> > > Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ
> > > (b) Update your program to be able to do the vice verse of the above.
>
> > I think it's is asking to convert a 32-bit int to the dotted form.
>
> > It's a little known fact, but IP addresses are valid in non-dotted
> > long-int form. Spammers commonly use this trick to disguise their IP
> > addresses in emails from scanners.
>
> that is correct. don't read too much into it. i'm not trying to
> validate anything or any format, use old or new technology. it is
> simply to exercise your skills with numbers (specifically 32-bit/4-
> byte integers), string manipulation, and bitwise operations. if you
> wish to use different sizes of numbers, forms of addressing, IPv6,
> etc., that's up to you. don't forget about part (b), which is to take
> an IP address and turn it into a 32-bit integer.
>
> enjoy!
> -- wesley
>
> ps. since you're on p. 248, there is also a typo in the piece of code
> right above this exercise, Example 6.4, which is tied to exercise
> 6-7. "'fac_list'" should really be "`fac_list`", or even better,
> "repr(fac_list)". see the Errata at the book's websitehttp://core...
> for more details.
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> http://core...
>
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, cahttp://cyberwebcons...

Well, I think I may be way off on this one. . . here's what I came up
with. . . .

def int_to_IP(int):
'''Function accepts an integer and returns a string in the format
WWW.XXX.YYY.ZZZ'''
string = str(int)
return (string[0]*3 + '.' + string[1]*3 + '.' + string[2]*3 + '.'
+ string[3]*3)


number = int(raw_input('Enter the number(4 digits): '))

print (int_to_IP(number))