Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pygeoip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pygeoip
Commits
72430d4a
Commit
72430d4a
authored
Dec 04, 2012
by
steve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better & faster ip util
parent
e1af7d4e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
29 deletions
+4
-29
pygeoip/util.py
+4
-29
No files found.
pygeoip/util.py
View file @
72430d4a
...
...
@@ -33,34 +33,9 @@ def ip2long(ip):
@param ip: IPv4 or IPv6 address
@type ip: str
"""
if
ip
.
find
(
':'
)
>=
0
:
return
i
p2long_v6
(
ip
)
e
lse
:
return
i
p2long_v4
(
ip
)
try
:
return
i
nt
(
socket
.
inet_aton
(
ip
)
.
encode
(
'hex'
),
16
)
e
xcept
socket
.
error
:
return
i
nt
(
socket
.
inet_pton
(
socket
.
AF_INET6
,
ip
)
.
encode
(
'hex'
),
16
)
def
ip2long_v4
(
ip
):
"""
Convert a IPv4 address into a 32-bit integer.
@param ip: quad-dotted IPv4 address
@type ip: str
@return: network byte order 32-bit integer
@rtype: int
"""
return
int
(
socket
.
inet_aton
(
ip
)
.
encode
(
'hex'
),
16
)
def
ip2long_v6
(
ip
):
"""
Convert a IPv6 address into long.
@param ip: IPv6 address
@type ip: str
@return: network byte order long
@rtype: long
"""
return
int
(
socket
.
inet_pton
(
socket
.
AF_INET6
,
ip
)
.
encode
(
'hex'
),
16
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment