Search code examples
tcpftpftps

How does 192,168,1,2,7,138 convert to port 1930 on IP address 192.168.1.2


How do i deduce the port and ip from a number that FTP throws? For example 192,168,1,2,7,138 converts to 1930 on IP address 192.168.1.2?

What is the logic behind?


Solution

  • The first four numbers indicate client IP, the second two numbers indicate the client port number. It's a hex to dec conversion.

    16^2 * 7 + 138 = 1930
    

    The first number stands for 3-rd and 4-th bit of a hex number (port number), the second is for 1-st and 2-nd bit of a hex number. So we have

    7 = 07 in hex
    

    and

    138 = 8A in hex
    

    Altogether we have

    078A in hex which is 1930
    

    or you can just skip that and convert only the first number to dec which is for 3-d and 4-th bit because of that "shift". The second number is already converted.