ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

چه طور می شود ip یک کامپیوتر را از یک برنامه درآورد

 
Post new topic   Reply to topic    ParsX.com Forum Index -> ويژوال بيسيك .NET
View previous topic :: View next topic  
Author Message
alireza goodarzi
مهمون يكي دو روزه


Joined: 21 Nov 2005
Posts: 15

PostPosted: Sun Dec 04, 2005 10:54 pm    Post subject: چه طور می شود ip یک کامپیوتر را از یک برنامه درآورد Reply with quote

سلام منم
همان سریش قبلیه Laughing
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Dec 05, 2005 6:51 pm    Post subject: Reply with quote

Declare Function gethostname Lib "ws2_32.dll" (ByVal host_name As String, _
                                               ByVal namelen As Long) As Long

Private Sub cmdGet_Click()
    '----------------------------------------------------
    'pointer to HOSTENT structure returned by
    'the gethostbyname function
    Dim lngPtrToHOSTENT As Long
    '
    'structure which stores all the host info
    Dim udtHostent      As HOSTENT
    '
    'pointer to the IP address' list
    Dim lngPtrToIP      As Long
    '
    'byte array that contains elemets of an IP address
    Dim arrIpAddress()  As Byte
    '
    'result IP address string to add into the ListBox
    Dim strIpAddress    As String
    '
    'buffer string to receive the local system host name
    Dim strHostName As String * 256
    '
    'value returned by the gethostname function
    Dim lngRetVal As Long
    '----------------------------------------------------   
    '
    'Clear the ListBox control
    List1.Clear
    '
    'Get the local host name
    lngRetVal = gethostname(strHostName, 256)
    '
    If lngRetVal = SOCKET_ERROR Then
        ShowErrorMsg (Err.LastDllError)
        Exit Sub
    End If
    '
    Text1.Text = Left(strHostName, InStr(1, strHostName, Chr(0)) - 1)
    '
    'Call the gethostbyname Winsock API function
    'to get pointer to the HOSTENT structure
    lngPtrToHOSTENT = GetHostByName(Trim$(Text1.Text))
    '
    'Check the lngPtrToHOSTENT value
    If lngPtrToHOSTENT = 0 Then
        '
        'If the gethostbyname function has returned 0
        'the function execution is failed. To get
        'error description call the ShowErrorMsg
        'subroutine
        '
        ShowErrorMsg (Err.LastDllError)
        '
    Else
        '
        'The gethostbyname function has found the address
        '
        'Copy retrieved data to udtHostent structure
        RtlMoveMemory udtHostent, lngPtrToHOSTENT, LenB(udtHostent)
        '
        'Now udtHostent.hAddrList member contains
        'an array of IP addresses
        '
        'Get a pointer to the first address
        RtlMoveMemory lngPtrToIP, udtHostent.hAddrList, 4
        '
        Do Until lngPtrToIP = 0
            '
            'Prepare the array to receive IP address values
            ReDim arrIpAddress(1 To udtHostent.hLength)
            '
            'move IP address values to the array
            RtlMoveMemory arrIpAddress(1), lngPtrToIP, udtHostent.hLength
            '
            'build string with IP address
            For i = 1 To udtHostent.hLength
                strIpAddress = strIpAddress & arrIpAddress(i) & "."
            Next
            '
            'remove the last dot symbol
            strIpAddress = Left$(strIpAddress, Len(strIpAddress) - 1)
            '
            'Add IP address to the listbox
            List1.AddItem strIpAddress
            '
            'Clear the buffer
            strIpAddress = ""
            '
            'Get pointer to the next address
            udtHostent.hAddrList = udtHostent.hAddrList + LenB(udtHostent.hAddrList)
            RtlMoveMemory lngPtrToIP, udtHostent.hAddrList, 4
            '
         Loop
        '
    End If
    '
End Sub


مرجع
http://www.vbip.com/winsock-api/gethostname/gethostname-01.asp
Back to top
alireza goodarzi
مهمون يكي دو روزه


Joined: 21 Nov 2005
Posts: 15

PostPosted: Mon Dec 05, 2005 9:59 pm    Post subject: Reply with quote

بیشتر توضیح دهید.Please Embarassed
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Thu Dec 08, 2005 1:30 pm    Post subject: Reply with quote

اين پروژه رو دانلود كن و اجرا كن .
اينم توضيح
http://www.vbip.com/winsock-api/gethostname/GetLocalHost.zip
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> ويژوال بيسيك .NET All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum