Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.toolbox
Commits
11845745
Commit
11845745
authored
Oct 20, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Release 0.41.0: add is-local-tcp-port-opened script
parent
c50a0c1e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletion
+41
-1
setup.py
setup.py
+2
-1
slapos/promise/__init__.py
slapos/promise/__init__.py
+0
-0
slapos/promise/islocaltcpportopened/__init__.py
slapos/promise/islocaltcpportopened/__init__.py
+39
-0
No files found.
setup.py
View file @
11845745
...
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
...
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
import
glob
import
glob
import
os
import
os
version
=
'0.4
0.4
'
version
=
'0.4
1.0
'
name
=
'slapos.toolbox'
name
=
'slapos.toolbox'
long_description
=
open
(
"README.txt"
).
read
()
+
"
\
n
"
+
\
long_description
=
open
(
"README.txt"
).
read
()
+
"
\
n
"
+
\
open
(
"CHANGES.txt"
).
read
()
+
"
\
n
"
open
(
"CHANGES.txt"
).
read
()
+
"
\
n
"
...
@@ -53,6 +53,7 @@ setup(name=name,
...
@@ -53,6 +53,7 @@ setup(name=name,
entry_points
=
{
entry_points
=
{
'console_scripts'
:
[
'console_scripts'
:
[
'agent = slapos.agent.agent:main [agent]'
,
'agent = slapos.agent.agent:main [agent]'
,
'is-local-tcp-port-opened = slapos.promise.islocaltcpportopened:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
...
...
slapos/promise/__init__.py
0 → 100644
View file @
11845745
slapos/promise/islocaltcpportopened/__init__.py
0 → 100755
View file @
11845745
#!/usr/bin/env python
"""
Check if a specific ip address and port is listening.
No connection establishment is done during the check.
Uses:
- /proc/net/tcp
- /proc/net/tcp6
"""
import
sys
import
socket
import
struct
assert
struct
.
calcsize
(
'I'
)
==
4
def
is_local_tcp_port_opened
(
ip_address
,
port
):
family
=
socket
.
getaddrinfo
(
ip_address
,
0
)[
0
][
0
]
conf
=
{
socket
.
AF_INET6
:
(
4
,
"/proc/net/tcp6"
),
socket
.
AF_INET
:
(
1
,
"/proc/net/tcp"
),
}
int_count
=
conf
[
family
][
0
]
tcp_path
=
conf
[
family
][
1
]
ip_addr_hex
=
(
'%08X'
*
int_count
)
%
struct
.
unpack
(
'I'
*
int_count
,
socket
.
inet_pton
(
family
,
ip_address
))
full_addr_hex
=
ip_addr_hex
+
":%04X"
%
port
return
any
(
full_addr_hex
==
line
.
split
()[
1
]
for
line
in
open
(
tcp_path
).
readlines
())
def
main
():
if
is_local_tcp_port_opened
(
sys
.
argv
[
1
],
int
(
sys
.
argv
[
2
])):
return
0
return
1
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
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