Announcement

Collapse
No announcement yet.

HOST NAME

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wayne Diamond
    replied
    Scott,
    Converting those last two numbers to port and vice versa is easy
    eg, ",7,208" becomes 2000, and 2000 becomes ",7,208"

    Here's some VB source, sorry i dont have the time to convert it to PB but it's pretty straight forward!
    Sorry im 9 months late too!
    ive left my commenting in, hope it makes sense

    Code:
    Private Sub Form_Load()
    On Error Resume Next
    'If you want the FTP server to connect to you on port 2000,
    'you can find out the last two values of the PORT command
    'by using PortString(tcpPort)
    Dim PortStr As String
    PortStr = PortString(2000)   '= 7,208
    MsgBox "2000=" & PortStr
    
    'If you want to resolve "7,208" back to 2000, use this:
    Dim PortStr2 As Integer
    PortStr2 = PortResolve("7", "208") '= 2000
    MsgBox "7,208=" & CStr(PortStr2)
    End Sub
    
    Public Function Dec2Bin(ByVal nDec As Integer) As String
    On Error Resume Next
        Dim i As Integer
        Dim j As Integer
        Dim sHex As String
        Const HexChar As String = "0123456789ABCDEF"
        sHex = Hex(nDec) 'That the only part that is different
        For i = 1 To Len(sHex)
            nDec = InStr(1, HexChar, Mid(sHex, i, 1)) - 1
            For j = 3 To 0 Step -1
                Dec2Bin = Dec2Bin & nDec \ 2 ^ j
                nDec = nDec Mod 2 ^ j
            Next j
        Next i
        'Dec2Bin = Right("00000000" & Dec2Bin, 8)
    End Function
    Function Bin2Dec(bite) As Integer
    On Error Resume Next
        Y = Len(bite) - 1
        For x = 1 To Len(bite)
            conv_bin_dec = conv_bin_dec + ((2 ^ Y)) * (Mid$(bite, x, 1))
            Y = Y - 1
        Next x
    Bin2Dec = conv_bin_dec
    End Function
    
    Public Function PortString(tcpPort As Integer) As String
    On Error Resume Next
    CZ = Dec2Bin(tcpPort)
    FZ1 = Left(CZ, 4)
    FZ2 = Right(CZ, Len(CZ) - 4)
    PortString = Trim(CStr(Bin2Dec(FZ1))) & "," & Trim(CStr(Bin2Dec(FZ2)))
    End Function
    Public Function PortResolve(p1 As String, p2 As String) As Integer
    On Error Resume Next
     CZ = Dec2Bin(Val(p1)) & Dec2Bin(Val(p2))
     PortResolve = Bin2Dec(CZ)
    End Function

    ------------------


    [This message has been edited by Wayne Diamond (edited November 07, 2000).]

    Leave a comment:


  • Scott Turchin
    replied
    Thanks LancE!

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    HOST ADDR(index&) TO ip&

    The index& value is the key...

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    OK Given this information from the help file, can someone refresh my memory as to determine which IP addresses the machine has? Say it has two adapters with TCP/IP bound to both?

    TCP OPEN [SERVER [ADDR ip&]] PORT p& | srvc$ AT host$ AS fnum& [TIMEOUT timeoutval]

    If ADDR is not specified, the primary IP address for the computer is used. (OK SO where do we get the second IP?)



    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    Scratch that, got it from the SMTP example:

    Host Addr To hTCP
    Host Name hTCP To localhost


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    started a topic HOST NAME

    HOST NAME

    So I am working on an FTP server, the client returns this string:

    PORT 192,168,10,2,5,186


    Meaning it(The client) is 192.168.10.2 and p1 and p2 I am confused on. (5 and 186 respectively)

    The client is requesting a DATA PORT, anyone have experience with this RFC for ftp?

    What i want to do is get MY IP address from the HOST NAME, and I assume I have no information, host name or IP address, and I remember seeing a post about how to specify which IP address if te machine has multiple adapters..

    Can someone send me that post?

    Scott

    -------------
    Scott
    mailto:[email protected][email protected]</A>
Working...
X