Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
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
outils
question2answer
Commits
124183b0
Commit
124183b0
authored
Feb 07, 2016
by
Daniel Ruf
Committed by
Scott
Feb 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added ipv6_numeric and ipv6_expand
parent
c5d5ef64
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
qa-base.php
qa-include/qa-base.php
+42
-0
No files found.
qa-include/qa-base.php
View file @
124183b0
...
...
@@ -202,6 +202,48 @@
if
(
QA_PASSWORD_HASH
)
{
require_once
QA_INCLUDE_DIR
.
'vendor/password_compat.php'
;
}
// http://stackoverflow.com/a/18277167
function
ipv6_numeric
(
$ip
)
{
$binNum
=
''
;
foreach
(
unpack
(
'C*'
,
inet_pton
(
$ip
))
as
$byte
)
{
$binNum
.=
str_pad
(
decbin
(
$byte
),
8
,
"0"
,
STR_PAD_LEFT
);
}
return
base_convert
(
ltrim
(
$binNum
,
'0'
),
2
,
10
);
}
// http://stackoverflow.com/a/12095836/753676
function
ipv6_expand
(
$ip
){
$ipv6_wildcard
=
false
;
$wildcards
=
''
;
$wildcards_matched
=
array
();
if
(
strpos
(
$ip
,
"*"
)
!==
false
){
$ipv6_wildcard
=
true
;
}
if
(
$ipv6_wildcard
){
$wildcards
=
explode
(
":"
,
$ip
);
foreach
(
$wildcards
as
$index
=>
$value
){
if
(
$value
==
"*"
){
$wildcards_matched
[]
=
$index
;
$wildcards
[
$index
]
=
"0"
;
}
}
$ip
=
implode
(
$wildcards
,
":"
);
}
$hex
=
unpack
(
"H*hex"
,
inet_pton
(
$ip
));
$ip
=
substr
(
preg_replace
(
"/([A-f0-9]
{
4
}
)/"
,
"$1:"
,
$hex
[
'hex'
]),
0
,
-
1
);
if
(
$ipv6_wildcard
){
$wildcards
=
explode
(
":"
,
$ip
);
foreach
(
$wildcards_matched
as
$index
=>
$value
){
$wildcards
[
$value
]
=
"*"
;
}
$ip
=
implode
(
$wildcards
,
":"
);
}
return
$ip
;
}
}
...
...
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