Accueil > > > 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
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
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
VB.NET ET COMBOBOXVB.NET ET COMBOBOX par minouthebreaker
Cliquez pour lire la suite par minouthebreaker
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|