ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Bash programming - How to find an active SCTP path
    Programming/Java_Shell_Python 2021. 3. 10. 11:54

     
    <Purpose>
    This script shows what are IPs of active SCTP path.
     
    <How to run>
    1. copy and paste my scripts into your shell file.
    2. chmod 755 <your filename>.sh
    3. ./<your filename>.sh
     
    <Bash Scripts>

    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    #!/bin/bash
     
    # This is to get input about port number and IPs
    printf "What local port number do you want to see about a current SCTP path(port number only): "
    read portNumber
     
    printf "What is primary local IPs : "
    read lpIP
     
    printf "What is secondary local IPs : "
    read lsIP
     
    printf "What is primary remote IPs : "
    read rpIP
     
    printf "What is secondary remote IPs : "
    read rsIP
     
    # This is to remove files which this scripts is using
    rm -f tcpdumpResult awkResult1 awkResult2 rlpIP rlsIP rrpIP rrsIP
     
    # This is to run TCPDUMP to catch SCTP path
    timeout 30 tcpdump -i any -n port $portNumber | grep -v ethertype >> tcpdumpResult
     
    # This is to fetch local IP from the tcpdump result
    awk '{print $3}' tcpdumpResult >> awkResult1
    # This is to fetch remote IP from the tcpdump result
    awk '{print $5}' tcpdumpResult >> awkResult2
     
    # This is to count local primary IP and write the number in rlpIP file
    grep --i $lpIP awkResult1 | wc ->> ./rlpIP
    # This is to count local secondary IP and write the number in rlsIP file
    grep --i $lsIP awkResult1 | wc ->> ./rlsIP
    # This is to count remote primary IP and write the number in rrpIP file
    grep --i $rpIP awkResult2 | wc ->> ./rrpIP
    # This is to count remote secondary IP and write the number in rrsIP file
    grep --i $rsIP awkResult2 | wc ->> ./rrsIP
     
     
    # This is to put the number rlpIP into variable 
    export rlpIP=`cat ./rlpIP`
    export rlsIP=`cat ./rlsIP`
    export rrpIP=`cat ./rrpIP`
    export rrsIP=`cat ./rrsIP`
     
     
    # This is to compare counts between the primary with secondary IPs for Local
    if [ $rlpIP -gt $rlsIP ]
    then
            echo "The current SCTP LOCAL IP: $lpIP"
    else
            echo "The current SCTP LOCAL IP: $lsIP"
    fi
     
    # This is to compare counts between the primary with secondary IPs for remote 
    if [ $rrpIP -gt $rrsIP ]
    then
            echo "The current SCTP REMOTE IP: $rpIP"
    else
            echo "The current SCTP REMOTE IP: $rsIP"
    fi
     
    # This is to remove files which this scripts used
    rm -f tcpdumpResult awkResult1 awkResult2 rlpIP rlsIP rrpIP rrsIP
     
    exit 0
     
    cs

    'Programming > Java_Shell_Python' 카테고리의 다른 글

    TCP server for IMF by python (1)  (0) 2020.05.06

    댓글

Designed by Tistory.