begin process at 2012 02 12 11:39:07
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseau & Internet

 > TROUVER L'IP D' UN SITE INTERNET AVEC L 'API WINSOCK

TROUVER L'IP D' UN SITE INTERNET AVEC L 'API WINSOCK


 Information sur la source

Note :
6,5 / 10 - par 2 personnes
6,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Réseau & Internet Niveau :Initié Date de création :26/08/2002 Date de mise à jour :26/08/2002 12:05:01 Vu :3 821

Auteur : SuperClic

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

Ben, ca fait ce que je vous ai dit. C' est pour trouver l' IP d' un site utilisant le protocole HTTP avec Winsck.dll

Il faut pas marquer "htp://" dans la boite

Source

  • Private Const AF_INET = 2
  • Private Const INVALID_SOCKET = -1
  • Private Const WSA_DESCRIPTIONLEN = 256
  • Private Const WSA_DescriptionSize = WSA_DESCRIPTIONLEN + 1
  • Private Const WSA_SYS_STATUS_LEN = 128
  • Private Const WSA_SysStatusSize = WSA_SYS_STATUS_LEN + 1
  • Private Const INADDR_NONE = &HFFFF
  • Private Const hostent_size = 16
  • Private Type WSADataType
  • wVersion As Integer
  • wHighVersion As Integer
  • szDescription As String * WSA_DescriptionSize
  • szSystemStatus As String * WSA_SysStatusSize
  • iMaxSockets As Integer
  • iMaxUdpDg As Integer
  • lpVendorInfo As Long
  • End Type
  • Private Type HostEnt
  • h_name As Long
  • h_aliases As Long
  • h_addrtype As Integer
  • h_length As Integer
  • h_addr_list As Long
  • End Type
  • Private Type sockaddr
  • sin_family As Integer
  • sin_port As Integer
  • sin_addr As Long
  • sin_zero As String * 8
  • End Type
  • Private Declare Function WSAIsBlocking Lib "wsock32.dll" () As Long
  • Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
  • Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVR As Long, lpWSAD As WSADataType) As Long
  • Private Declare Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Integer
  • Private Declare Function ntohs Lib "wsock32.dll" (ByVal netshort As Long) As Integer
  • Private Declare Function socket Lib "wsock32.dll" (ByVal af As Long, ByVal s_type As Long, ByVal protocol As Long) As Long
  • Private Declare Function closesocket Lib "wsock32.dll" (ByVal s As Long) As Long
  • Private Declare Function Connect Lib "wsock32.dll" Alias "connect" (ByVal s As Long, addr As sockaddr, ByVal namelen As Long) As Long
  • Private Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long
  • Private Declare Function gethostbyname Lib "wsock32.dll" (ByVal host_name As String) As Long
  • Private Declare Sub MemCopy Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)
  • Private Declare Function inet_ntoa Lib "wsock32.dll" (ByVal inn As Long) As Long
  • Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
  • Private Declare Function WSACancelBlockingCall Lib "wsock32.dll" () As Long
  • Private saZero As sockaddr
  • Private WSAStartedUp As Boolean
  • Private lSocket As Long
  • '*****************************************************
  • Private Sub Form_Load()
  • Dim sSave As String
  • '************ Demarrage de WinSock
  • Dim StartupData As WSADataType
  • If Not WSAStartedUp Then
  • If Not WSAStartup(&H101, StartupData) Then
  • WSAStartedUp = True
  • sSave = StartupData.szDescription
  • Else
  • WSAStartedUp = False
  • End If
  • End If
  • site = InputBox("Site internet à chercher (faut pas mettre http://):", "Recherche d' IP")
  • ' *** version de winsock
  • If InStr(1, sSave, Chr$(0)) > 0 Then sSave = Left$(sSave, InStr(1, sSave, Chr$(0)) - 1)
  • 'connecte au site
  • ip = ConnectSock(site, 80, 0, False)
  • If Len(ip) >= 14 Then MsgBox ip
  • End Sub
  • Function ConnectSock(ByVal Host$, ByVal Port&, retIpPort$, ByVal Async%) As String
  • Dim s&, SelectOps&, Dummy&
  • Dim sockin As sockaddr
  • SockReadBuffer$ = ""
  • sockin = saZero
  • sockin.sin_family = AF_INET
  • sockin.sin_port = htons(Port) 'port
  • If sockin.sin_port = INVALID_SOCKET Then
  • ConnectSock = INVALID_SOCKET
  • MsgBox "Problème de port!"
  • Exit Function
  • End If
  • ' recupere add IP bizzare(-60...)
  • sockin.sin_addr = GetHostByNameAlias(Host$)
  • ' verifie
  • If sockin.sin_addr = INADDR_NONE Then
  • ConnectSock = INVALID_SOCKET
  • MsgBox "Problème d' addrese!"
  • Exit Function
  • End If
  • retIpPort$ = getascip$(sockin.sin_addr) & ":" & ntohs(sockin.sin_port)
  • ConnectSock = retIpPort$
  • End Function
  • ' recuperer IP
  • Function GetHostByNameAlias(ByVal hostname$) As Long
  • On Error Resume Next
  • Dim phe&
  • Dim heDestHost As HostEnt
  • Dim addrList&
  • Dim retIP&
  • retIP = inet_addr(hostname) 'doit etre =-1
  • If retIP = INADDR_NONE Then
  • phe = gethostbyname(hostname) 'connection-->donne 1IP
  • If phe <> 0 Then
  • MemCopy heDestHost, ByVal phe, hostent_size
  • MemCopy addrList, ByVal heDestHost.h_addr_list, 4
  • MemCopy retIP, ByVal addrList, heDestHost.h_length
  • Else
  • retIP = INADDR_NONE
  • End If
  • End If
  • GetHostByNameAlias = retIP '=?
  • If Err Then GetHostByNameAlias = INADDR_NONE
  • End Function
  • Function getascip(ByVal inn As Long) As String
  • On Error Resume Next
  • Dim lpStr&
  • Dim nStr&
  • Dim retString$
  • retString = String(32, 0) '32*chr(0) :petits carrés
  • lpStr = inet_ntoa(inn)
  • If lpStr = 0 Then
  • getascip = "255.255.255.255"
  • Exit Function
  • End If
  • nStr = lstrlen(lpStr) '14
  • If nStr > 32 Then nStr = 32
  • MemCopy ByVal retString, ByVal lpStr, nStr
  • retString = Left(retString, nStr) 'ip+carres
  • getascip = retString 'IP !!!
  • If Err Then getascip = "255.255.255.255"
  • End Function
  • Private Sub Form_Unload() 'Cancel As Integer)
  • Dim Ret&
  • 'Ferme le socket
  • closesocket lSocket
  • 'Fin de winsock
  • If WSAIsBlocking() Then
  • Ret = WSACancelBlockingCall()
  • End If
  • Ret = WSACleanup()
  • WSAStartedUp = False
  • End Sub
Private Const AF_INET = 2
Private Const INVALID_SOCKET = -1
Private Const WSA_DESCRIPTIONLEN = 256
Private Const WSA_DescriptionSize = WSA_DESCRIPTIONLEN + 1
Private Const WSA_SYS_STATUS_LEN = 128
Private Const WSA_SysStatusSize = WSA_SYS_STATUS_LEN + 1
Private Const INADDR_NONE = &HFFFF
Private Const hostent_size = 16
Private Type WSADataType
    wVersion As Integer
    wHighVersion As Integer
    szDescription As String * WSA_DescriptionSize
    szSystemStatus As String * WSA_SysStatusSize
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpVendorInfo As Long
End Type
Private Type HostEnt
    h_name As Long
    h_aliases As Long
    h_addrtype As Integer
    h_length As Integer
    h_addr_list As Long
End Type
Private Type sockaddr
    sin_family As Integer
    sin_port As Integer
    sin_addr As Long
    sin_zero As String * 8
End Type

Private Declare Function WSAIsBlocking Lib "wsock32.dll" () As Long
Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVR As Long, lpWSAD As WSADataType) As Long
Private Declare Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Integer
Private Declare Function ntohs Lib "wsock32.dll" (ByVal netshort As Long) As Integer
Private Declare Function socket Lib "wsock32.dll" (ByVal af As Long, ByVal s_type As Long, ByVal protocol As Long) As Long
Private Declare Function closesocket Lib "wsock32.dll" (ByVal s As Long) As Long
Private Declare Function Connect Lib "wsock32.dll" Alias "connect" (ByVal s As Long, addr As sockaddr, ByVal namelen As Long) As Long
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long
Private Declare Function gethostbyname Lib "wsock32.dll" (ByVal host_name As String) As Long
Private Declare Sub MemCopy Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)
Private Declare Function inet_ntoa Lib "wsock32.dll" (ByVal inn As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
Private Declare Function WSACancelBlockingCall Lib "wsock32.dll" () As Long
Private saZero As sockaddr
Private WSAStartedUp As Boolean
Private lSocket As Long

'*****************************************************



Private Sub Form_Load()
    Dim sSave As String


'************ Demarrage de WinSock
    
        Dim StartupData As WSADataType
    If Not WSAStartedUp Then
        If Not WSAStartup(&H101, StartupData) Then
            WSAStartedUp = True
            sSave = StartupData.szDescription
        Else
            WSAStartedUp = False
        End If
    End If

site = InputBox("Site internet à chercher (faut pas mettre http://):", "Recherche d' IP")
    
    ' *** version de winsock
    
If InStr(1, sSave, Chr$(0)) > 0 Then sSave = Left$(sSave, InStr(1, sSave, Chr$(0)) - 1)
    'connecte au site
ip = ConnectSock(site, 80, 0, False)
If Len(ip) >= 14 Then MsgBox ip
End Sub


Function ConnectSock(ByVal Host$, ByVal Port&, retIpPort$, ByVal Async%) As String
    Dim s&, SelectOps&, Dummy&
    Dim sockin As sockaddr
    SockReadBuffer$ = ""
    sockin = saZero
    sockin.sin_family = AF_INET
    sockin.sin_port = htons(Port)  'port
    If sockin.sin_port = INVALID_SOCKET Then
        ConnectSock = INVALID_SOCKET
        MsgBox "Problème de port!"
        Exit Function
    End If
' recupere add IP bizzare(-60...)
    sockin.sin_addr = GetHostByNameAlias(Host$)

' verifie
    If sockin.sin_addr = INADDR_NONE Then
        ConnectSock = INVALID_SOCKET
        MsgBox "Problème d' addrese!"
        Exit Function
    End If
retIpPort$ = getascip$(sockin.sin_addr) & ":" & ntohs(sockin.sin_port)

ConnectSock = retIpPort$

End Function
' recuperer IP
Function GetHostByNameAlias(ByVal hostname$) As Long
    On Error Resume Next
    Dim phe&
    Dim heDestHost As HostEnt
    Dim addrList&
    Dim retIP&
    retIP = inet_addr(hostname) 'doit etre =-1
    If retIP = INADDR_NONE Then
phe = gethostbyname(hostname) 'connection-->donne 1IP
        If phe <> 0 Then
      MemCopy heDestHost, ByVal phe, hostent_size
      MemCopy addrList, ByVal heDestHost.h_addr_list, 4
      MemCopy retIP, ByVal addrList, heDestHost.h_length
        Else
            retIP = INADDR_NONE
        End If
    End If
    GetHostByNameAlias = retIP '=?
    If Err Then GetHostByNameAlias = INADDR_NONE
End Function


Function getascip(ByVal inn As Long) As String
    On Error Resume Next
    Dim lpStr&
    Dim nStr&
    Dim retString$
    retString = String(32, 0) '32*chr(0) :petits carrés
    lpStr = inet_ntoa(inn)
    If lpStr = 0 Then
        getascip = "255.255.255.255"
        Exit Function
    End If
    nStr = lstrlen(lpStr)      '14
    If nStr > 32 Then nStr = 32
    MemCopy ByVal retString, ByVal lpStr, nStr
    retString = Left(retString, nStr) 'ip+carres
    getascip = retString 'IP !!!
    If Err Then getascip = "255.255.255.255"
End Function






Private Sub Form_Unload() 'Cancel As Integer)
    Dim Ret&
    
  
    'Ferme le socket
closesocket lSocket
   'Fin de winsock
If WSAIsBlocking() Then
    Ret = WSACancelBlockingCall()
End If
Ret = WSACleanup()
WSAStartedUp = False


End Sub



 Sources du même auteur

LISTER LES PROCESSUS ACTIFS AVEC LES API
Source avec Zip S' AMUSER AVEC LES LECTEURS CD (BUG CORRIGÉ)
Source avec Zip DÉMINEUR SOUS EXCEL
CRÉATION OU MODIFICATION DE RACCOURCI (COMPATIBLE VBS)

 Sources de la même categorie

Source avec Zip Source avec une capture GESTIONNAIRE DE TÉLÉCHARGEMENT, AVEC REPRISE ET MULTITHREADI... par Madx23
Source avec Zip Source avec une capture CONVERTIR DU TEXTE RTF EN CODE HTML ET VICE-VERSA par vicosta
Source avec Zip Source avec une capture DICTIONAIRE TEXT/AUDIO/VISUELLE ANGLAIS AVEC WEBBROWSER CONT... par majnounmajda
Source avec Zip Source .NET (Dotnet) NSLOOKUP EN VB.NET OU COMMENT FAIRE UNE REQÛETE DNS EN PRÉCI... par ShareVB
Source avec Zip Source avec une capture MINI SEVEUR HTTP AVEC INTERFACE GRAPHIQUE ET IMPLÉMENTATIONS... par lemout

Commentaires et avis

Commentaire de Mindiell le 26/08/2002 15:35:05

euh, ca serait pas 1 000 000 de fois plus simple de faire un bete ping nomdusite ???

Commentaire de SuperClic le 27/08/2002 14:24:22

Euh ... C' est possible en effet, mais Winsock devrait offrir plus de fonctionnalités.

Commentaire de babeuk le 28/08/2002 00:22:25

si je peux me permettre il y a bcp plus simple pour trouver l'ip d'un site avec winsock !!!

Private Sub Command1_Click()
Winsock1.Connect "www.babeuk.net", 80
End Sub

Private Sub Winsock1_Connect()
MsgBox Winsock1.RemoteHostIP
Winsock1.Close
End Sub

Commentaire de SuperClic le 28/08/2002 12:16:13

Ouais, mais ta méthode nescessite visiblement le controle winsck.ocx qui est rarement livré d'office avec Windows.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,856 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales