0

I have such string: "172.17.0.030". I should return False cuz it's not a valid ip address. How can I check that last octet contains not valid value (not in base of 10)?

Volodymyr
  • 1,192
  • 21
  • 42
  • 1
    but `030` is correct value in base 10 ? try `int('030')` or `int('030', 10)`. You have to define why it is not valid. – furas Dec 08 '16 at 11:23
  • Why is it not valid? I can ping it (and that last octet gets interpreted as 24 in decimal). `PING 172.17.0.030 (172.17.0.24): 56 data bytes` – Thilo Dec 08 '16 at 11:23
  • *because As @Lafexlos said, it is valid, and in base 10. other bases have a prefix(0x for example.). If you want to check if it has leading 0's, you can split on the dot, and check with the function "string.startswith("0")". – ShadowFlame Dec 08 '16 at 11:24
  • @ShadowFlame, yep. I want to check on leading zero's. And I intentionally have added in the 3-rd octet "0"..cuz startswith("0") isn't enough. – Volodymyr Dec 08 '16 at 11:43
  • @Thilo, emm...yes, it's valid in base of 10 (it's 24)...but I meant that I should add handling such case when error occured during typing "030" (for instance) instead of "30". – Volodymyr Dec 08 '16 at 11:43
  • @ascentman: startswith("0") and not "0" and not "00" and not "000" (or a regex for the 0*n matching) – ShadowFlame Dec 08 '16 at 14:05

0 Answers0