Core Python Programming . . .

F

FireNWater

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!!!
 
P

Paul Rubin

FireNWater said:
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.
 
M

Mike Driscoll

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
 
Y

Yu-Xi Lim

Mike said:
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.
 
F

FireNWater

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?
 
Y

Yu-Xi Lim

FireNWater said:
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.
 
J

Jorgen Grahn

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
 
W

wesley chun

6-11 Conversion.
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://corepython.com
for more details.

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

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

FireNWater

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://corepython.com
for more details.

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

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

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))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top