diff options
author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-06-17 14:24:42 +0000 |
---|---|---|
committer | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-06-17 14:48:28 +0000 |
commit | 20eec3e8a4341b866d570837dcbd93d15b3feb26 (patch) | |
tree | 306b3e6bbdc60e6037216adc3d5026629a41a830 /python/vyos/utils/network.py | |
parent | 49e2822e9775c1c38a067bdc2e92ab5fd69eac95 (diff) | |
download | vyos-1x-20eec3e8a4341b866d570837dcbd93d15b3feb26.tar.gz vyos-1x-20eec3e8a4341b866d570837dcbd93d15b3feb26.zip |
vyos.utils: T5195: add vyos.utils.network
Diffstat (limited to 'python/vyos/utils/network.py')
-rw-r--r-- | python/vyos/utils/network.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py new file mode 100644 index 000000000..72b7ca6da --- /dev/null +++ b/python/vyos/utils/network.py @@ -0,0 +1,30 @@ +# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. + +import os + + +def get_protocol_by_name(protocol_name): + """Get protocol number by protocol name + + % get_protocol_by_name('tcp') + % 6 + """ + import socket + try: + protocol_number = socket.getprotobyname(protocol_name) + return protocol_number + except socket.error: + return protocol_name |