summaryrefslogtreecommitdiffstats
path: root/docker/storperf-master/storperf/utilities/ip_helper.py
blob: 06087b01ed71259934faa5f4df1a72788c0f331a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
##############################################################################
# Copyright (c) 2019 VMware and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################


def parse_address_and_port(address):
    port = 22
    if '.' in address:
        # this is IPv4
        if ':' in address:
            host = address.split(':')[0]
            port = int(address.split(':')[1])
        else:
            host = address
    else:
        if ']' in address:
            # this is IPv6
            host = address.split(']')[0].split('[')[1]
            port = int(address.split(']')[1].split(':')[1])
        else:
            host = address
    return (host, port)