Built in libs to give untrimmed ipv6 address? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceRemove leading zeros in IP address using PythonMaximum length of the textual representation of an IPv6 address?python 3: ipaddr/netaddr moduleswhat exactly is passed as “address” in sendto for ipv6'import site' failed; use -v for tracebackDjango auto deployment using FabricNot able to get multiple strings output from python script using c#Tensorflow-GPU Installation ImportError: DLL load failed: The specified module could not be foundImportError: No module named 'pip._vendor.requests' for python3Changing which Python Coderunner 3.0 uses to Anaconda's pythonPython Module Not Found, Yet Installed and in Search Path
Circular reasoning in L'Hopital's rule
How to support a colleague who finds meetings extremely tiring?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Huge performance difference of the command find with and without using %M option to show permissions
Make it rain characters
1960s short story making fun of James Bond-style spy fiction
How do you keep chess fun when your opponent constantly beats you?
Homework question about an engine pulling a train
Didn't get enough time to take a Coding Test - what to do now?
Can the DM override racial traits?
Intergalactic human space ship encounters another ship, character gets shunted off beyond known universe, reality starts collapsing
Word for: a synonym with a positive connotation?
Do I have Disadvantage attacking with an off-hand weapon?
What information about me do stores get via my credit card?
How do I design a circuit to convert a 100 mV and 50 Hz sine wave to a square wave?
Word to describe a time interval
should truth entail possible truth
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
What happens to a Warlock's expended Spell Slots when they gain a Level?
60's-70's movie: home appliances revolting against the owners
Using dividends to reduce short term capital gains?
US Healthcare consultation for visitors
different output for groups and groups USERNAME after adding a username to a group
How to determine omitted units in a publication
Built in libs to give untrimmed ipv6 address?
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceRemove leading zeros in IP address using PythonMaximum length of the textual representation of an IPv6 address?python 3: ipaddr/netaddr moduleswhat exactly is passed as “address” in sendto for ipv6'import site' failed; use -v for tracebackDjango auto deployment using FabricNot able to get multiple strings output from python script using c#Tensorflow-GPU Installation ImportError: DLL load failed: The specified module could not be foundImportError: No module named 'pip._vendor.requests' for python3Changing which Python Coderunner 3.0 uses to Anaconda's pythonPython Module Not Found, Yet Installed and in Search Path
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
How do I trim leading zeroes in an ipv6 address string in python?
For eg: I need 1:1:1:1:1:1:0:1 to be trimmed to 1:1:1:1:1:1::1
I have tried using socket.inet_ntop and socket.inet_pton but they do not help in my case
#!/usr/bin/env python
import socket
import struct
address = '1:1:1:1:1:1:0:1'
addr = socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, address))
print (addr)
This prints the same string as the output 1:1:1:1:1:1:0:1
I have also tried the ipaddress lib which produces the same output as above.
#!/usr/bin/env python
import ipaddress
ip = '1:1:1:1:1:1:0:1'
print(str(ipaddress.ip_address(ip)))
I tried using the netaddr lib by referring to the top voted answer on this question but get an import error. I'm using Python 3.0.
I have also tried using this library but get an ImportError: No module named 'IPy' error
#!/usr/bin/env python
from IPy import IP
print(IP('1080:0:0:0:8:800:200C:417A'))
I'm surprised to find that no one has had a real clear cut solution in a built in library to solve this problem. Can someone help?
python-3.x ipv6 inet leading-zero
add a comment |
How do I trim leading zeroes in an ipv6 address string in python?
For eg: I need 1:1:1:1:1:1:0:1 to be trimmed to 1:1:1:1:1:1::1
I have tried using socket.inet_ntop and socket.inet_pton but they do not help in my case
#!/usr/bin/env python
import socket
import struct
address = '1:1:1:1:1:1:0:1'
addr = socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, address))
print (addr)
This prints the same string as the output 1:1:1:1:1:1:0:1
I have also tried the ipaddress lib which produces the same output as above.
#!/usr/bin/env python
import ipaddress
ip = '1:1:1:1:1:1:0:1'
print(str(ipaddress.ip_address(ip)))
I tried using the netaddr lib by referring to the top voted answer on this question but get an import error. I'm using Python 3.0.
I have also tried using this library but get an ImportError: No module named 'IPy' error
#!/usr/bin/env python
from IPy import IP
print(IP('1080:0:0:0:8:800:200C:417A'))
I'm surprised to find that no one has had a real clear cut solution in a built in library to solve this problem. Can someone help?
python-3.x ipv6 inet leading-zero
1
You are not supposed to compress a single0
. RFC 5952, Section 4, explains the proper IPv6 address formatting, including: "The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct."
– Ron Maupin
Mar 8 at 12:38
@RonMaupin Thanks for your clarification. socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, "1:1:1:1:1:1::1") returns 1:1:1:1:1:1:0:1. This very much solves my use case.
– Badri Narayanan
Mar 8 at 16:37
add a comment |
How do I trim leading zeroes in an ipv6 address string in python?
For eg: I need 1:1:1:1:1:1:0:1 to be trimmed to 1:1:1:1:1:1::1
I have tried using socket.inet_ntop and socket.inet_pton but they do not help in my case
#!/usr/bin/env python
import socket
import struct
address = '1:1:1:1:1:1:0:1'
addr = socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, address))
print (addr)
This prints the same string as the output 1:1:1:1:1:1:0:1
I have also tried the ipaddress lib which produces the same output as above.
#!/usr/bin/env python
import ipaddress
ip = '1:1:1:1:1:1:0:1'
print(str(ipaddress.ip_address(ip)))
I tried using the netaddr lib by referring to the top voted answer on this question but get an import error. I'm using Python 3.0.
I have also tried using this library but get an ImportError: No module named 'IPy' error
#!/usr/bin/env python
from IPy import IP
print(IP('1080:0:0:0:8:800:200C:417A'))
I'm surprised to find that no one has had a real clear cut solution in a built in library to solve this problem. Can someone help?
python-3.x ipv6 inet leading-zero
How do I trim leading zeroes in an ipv6 address string in python?
For eg: I need 1:1:1:1:1:1:0:1 to be trimmed to 1:1:1:1:1:1::1
I have tried using socket.inet_ntop and socket.inet_pton but they do not help in my case
#!/usr/bin/env python
import socket
import struct
address = '1:1:1:1:1:1:0:1'
addr = socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, address))
print (addr)
This prints the same string as the output 1:1:1:1:1:1:0:1
I have also tried the ipaddress lib which produces the same output as above.
#!/usr/bin/env python
import ipaddress
ip = '1:1:1:1:1:1:0:1'
print(str(ipaddress.ip_address(ip)))
I tried using the netaddr lib by referring to the top voted answer on this question but get an import error. I'm using Python 3.0.
I have also tried using this library but get an ImportError: No module named 'IPy' error
#!/usr/bin/env python
from IPy import IP
print(IP('1080:0:0:0:8:800:200C:417A'))
I'm surprised to find that no one has had a real clear cut solution in a built in library to solve this problem. Can someone help?
python-3.x ipv6 inet leading-zero
python-3.x ipv6 inet leading-zero
asked Mar 8 at 12:25
Badri NarayananBadri Narayanan
63
63
1
You are not supposed to compress a single0
. RFC 5952, Section 4, explains the proper IPv6 address formatting, including: "The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct."
– Ron Maupin
Mar 8 at 12:38
@RonMaupin Thanks for your clarification. socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, "1:1:1:1:1:1::1") returns 1:1:1:1:1:1:0:1. This very much solves my use case.
– Badri Narayanan
Mar 8 at 16:37
add a comment |
1
You are not supposed to compress a single0
. RFC 5952, Section 4, explains the proper IPv6 address formatting, including: "The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct."
– Ron Maupin
Mar 8 at 12:38
@RonMaupin Thanks for your clarification. socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, "1:1:1:1:1:1::1") returns 1:1:1:1:1:1:0:1. This very much solves my use case.
– Badri Narayanan
Mar 8 at 16:37
1
1
You are not supposed to compress a single
0
. RFC 5952, Section 4, explains the proper IPv6 address formatting, including: "The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct."– Ron Maupin
Mar 8 at 12:38
You are not supposed to compress a single
0
. RFC 5952, Section 4, explains the proper IPv6 address formatting, including: "The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct."– Ron Maupin
Mar 8 at 12:38
@RonMaupin Thanks for your clarification. socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, "1:1:1:1:1:1::1") returns 1:1:1:1:1:1:0:1. This very much solves my use case.
– Badri Narayanan
Mar 8 at 16:37
@RonMaupin Thanks for your clarification. socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, "1:1:1:1:1:1::1") returns 1:1:1:1:1:1:0:1. This very much solves my use case.
– Badri Narayanan
Mar 8 at 16:37
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063211%2fbuilt-in-libs-to-give-untrimmed-ipv6-address%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063211%2fbuilt-in-libs-to-give-untrimmed-ipv6-address%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You are not supposed to compress a single
0
. RFC 5952, Section 4, explains the proper IPv6 address formatting, including: "The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct."– Ron Maupin
Mar 8 at 12:38
@RonMaupin Thanks for your clarification. socket.inet_ntop(socket.AF_INET6,socket.inet_pton(socket.AF_INET6, "1:1:1:1:1:1::1") returns 1:1:1:1:1:1:0:1. This very much solves my use case.
– Badri Narayanan
Mar 8 at 16:37