Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F118310099
port-multi
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
port-multi
View Options
#!/usr/bin/python3
import
sys
import
re
from
vyos.util
import
read_file
services_file
=
'/etc/services'
def
get_services
():
names
=
[]
service_data
=
read_file
(
services_file
,
""
)
for
line
in
service_data
.
split
(
"
\n
"
):
if
not
line
or
line
[
0
]
==
'#'
:
continue
names
.
append
(
line
.
split
(
None
,
1
)[
0
])
return
names
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
>
1
:
ports
=
sys
.
argv
[
1
]
.
split
(
","
)
services
=
get_services
()
for
port
in
ports
:
if
re
.
match
(
'^[0-9]{1,5}-[0-9]{1,5}$'
,
port
):
port_1
,
port_2
=
port
.
split
(
'-'
)
if
int
(
port_1
)
not
in
range
(
1
,
65535
)
or
int
(
port_2
)
not
in
range
(
1
,
65535
):
print
(
f
'Error:
{
port
}
is not a valid port range'
)
sys
.
exit
(
1
)
if
int
(
port_1
)
>
int
(
port_2
):
print
(
f
'Error:
{
port
}
is not a valid port range'
)
sys
.
exit
(
1
)
elif
port
.
isnumeric
():
if
int
(
port
)
not
in
range
(
1
,
65535
):
print
(
f
'Error:
{
port
}
is not a valid port'
)
sys
.
exit
(
1
)
elif
port
not
in
services
:
print
(
f
'Error:
{
port
}
is not a valid service name'
)
sys
.
exit
(
1
)
else
:
sys
.
exit
(
2
)
sys
.
exit
(
0
)
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Sat, Oct 17, 12:55 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4380547
Default Alt Text
port-multi (1 KB)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment