Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
59bde2bf
Verified
Commit
59bde2bf
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
get primary ip address | refs
#28817
parent
96c18469
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_email.py
+2
-1
2 additions, 1 deletion
tests/test_email.py
utils.py
+20
-0
20 additions, 0 deletions
utils.py
with
22 additions
and
1 deletion
tests/test_email.py
+
2
−
1
View file @
59bde2bf
...
...
@@ -179,7 +179,7 @@ def check_spf(ip_addr: str, sender: str, domain: str) -> tuple:
errors
=
0
if
ip_address
(
ip_addr
).
is_private
:
u
.
info
(
"
{} is a private address, cannot check SPF
"
)
u
.
info
(
"
{} is a private address, cannot check SPF
"
.
format
(
ip_addr
)
)
elif
ip_addr
and
sender
:
# check spf
result
,
_
=
spf
.
check2
(
i
=
ip_addr
,
s
=
domain
,
h
=
""
)
...
...
@@ -215,6 +215,7 @@ def main():
(
socket
.
gethostbyname
(
relay
)
if
relay
else
None
)
or
conf
.
get
(
"
NETWORK_IP_NAT
"
)
or
conf
.
get
(
"
NETWORK_IP
"
)
or
u
.
get_ip
()
or
None
)
sender
=
conf
.
get
(
"
EMAIL_SENDER
"
)
or
None
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
20
−
0
View file @
59bde2bf
...
...
@@ -449,3 +449,23 @@ def mkcert(
cert_dir
+
"
/cert.pem
"
,
]
)
def
get_ip
()
->
str
:
"""
Get the
"
primary
"
ip address, the one used by the default route.
:return: IP address
:rtype: str
"""
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
try
:
# doesn't have to be reachable
s
.
connect
((
"
10.255.255.255
"
,
1
))
IP
=
s
.
getsockname
()[
0
]
except
Exception
:
IP
=
"
127.0.0.1
"
finally
:
s
.
close
()
return
IP
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment