Accueil > > > RÉSOUDRE UN NOM DNS EN ADRESSE IP EN UTILISANT WS2_32 (DLL WINSOCK)
RÉSOUDRE UN NOM DNS EN ADRESSE IP EN UTILISANT WS2_32 (DLL WINSOCK)
Information sur la source
Description
? GetIp("www.AtoutFox.org") retourne l'adresse IP d'un nom dns comme www.atoutfox.org en utilisant la DLL winsock Cordialement Francis FAURE
Source
- * -------------
- * Résoudre un nom DNS en adresse IP en utilisant WS2_32
- * par Francis FAURE
- * basé sur ressources : Microsoft.com, Fox.wikis.com
- * -------------
-
- * exemples :
- clear
- ? GetIp("www.AtoutFox.org")
- ? GetIp("www.foxforum.net")
- ? GetIp("www.foxprofr.com")
- ? GetIp("news.atoutfox.org")
- ? GetIp("xfrx.fr")
- ? GetIp("www.microsoft.com")
- ? GetIp("Fox.wikis.com")
-
-
- Function GetIP(p_host)
- local v_Struct, v_Buffer, v_IP, v_r, v_i
- p_host = Alltrim(p_host)
- v_r = ""
- #DEFINE HOSTENT_SIZE 16
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/hostent_2.asp
- * typedef struct hostent {
- * char FAR* h_name;
- * char FAR FAR** h_aliases;
- * short h_addrtype;
- * short h_length;
- * char FAR FAR** h_addr_list;
- * } hostent;
- *
-
- * -------------
- * initialisation WS2_32.DLL
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsastartup_2.asp
- *
- * -------------
- DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING lpWSAData
- if WSAStartup(0x202, Repli(Chr(0),512)) <> 0
- v_r = "0.0.0.0, Impossible d'initialiser WinSock (WS2_32.DLL) sur cette machine."
- wait windows v_r
- else
- * -------------
- * appel gethostname
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyname_2.asp
- *
- DECLARE INTEGER gethostbyname IN ws2_32 STRING host
- v_Struct = gethostbyname(p_host)
- * -------------
- * analyse
- if v_Struct = 0
- v_r = "0.0.0.0, host : "+p_host+" résolution IP impossible. Vérifier votre paramètre nom ou vos DNS."
- wait windows v_r
- else
- v_Buffer = Repli(Chr(0), HOSTENT_SIZE)
- v_IP = Chr(0) + Chr(0) + Chr(0) +Chr(0)
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k109_5731ba5b-a7a5-4883-87cf-543768a29a93.xml.asp
- *
- DECLARE RtlMoveMemory IN kernel32 STRING @Destination, INTEGER Source, INTEGER Longueur
- =RtlMoveMemory(@v_Buffer, v_Struct, HOSTENT_SIZE)
- * on s'intéresse donc au octets 13 14 15 et 16
- =RtlMoveMemory(@v_ip, b2dword(SubStr(v_Buffer,13,4)), 4)
- =RtlMoveMemory(@v_ip, b2dword(v_ip), 4)
- * -------------
- * retour sous forme de chaine
- * -------------
- for v_i=1 to 4
- v_r = v_r + Alltrim(str(Asc(Substr(v_ip,v_i,1)),3,0))+ Iif(v_i<4,".","")
- next
- clear dlls RtlMoveMemory
- endif
- * -------------
- * termine l'utilisation de WS2_32
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsacleanup_2.asp
- *
- DECLARE INTEGER WSACleanup IN ws2_32
- =WSACleanup()
- clear dlls WSACleanup
- clear dlls gethostbyname
- endif
- clear dlls WSAStartup
- return v_r
- * -------------
- FUNCTION b2dword(p_buffer)
- RETURN Asc(substr(p_buffer, 1,1)) + Bitlshift(Asc(substr(p_buffer, 2,1)),8) + Bitlshift(Asc(substr(p_buffer, 3,1)),16) + Bitlshift(Asc(substr(p_buffer, 4,1)),24)
- * -------------
* -------------
* Résoudre un nom DNS en adresse IP en utilisant WS2_32
* par Francis FAURE
* basé sur ressources : Microsoft.com, Fox.wikis.com
* -------------
* exemples :
clear
? GetIp("www.AtoutFox.org")
? GetIp("www.foxforum.net")
? GetIp("www.foxprofr.com")
? GetIp("news.atoutfox.org")
? GetIp("xfrx.fr")
? GetIp("www.microsoft.com")
? GetIp("Fox.wikis.com")
Function GetIP(p_host)
local v_Struct, v_Buffer, v_IP, v_r, v_i
p_host = Alltrim(p_host)
v_r = ""
#DEFINE HOSTENT_SIZE 16
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/hostent_2.asp
* typedef struct hostent {
* char FAR* h_name;
* char FAR FAR** h_aliases;
* short h_addrtype;
* short h_length;
* char FAR FAR** h_addr_list;
* } hostent;
*
* -------------
* initialisation WS2_32.DLL
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsastartup_2.asp
*
* -------------
DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING lpWSAData
if WSAStartup(0x202, Repli(Chr(0),512)) <> 0
v_r = "0.0.0.0, Impossible d'initialiser WinSock (WS2_32.DLL) sur cette machine."
wait windows v_r
else
* -------------
* appel gethostname
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyname_2.asp
*
DECLARE INTEGER gethostbyname IN ws2_32 STRING host
v_Struct = gethostbyname(p_host)
* -------------
* analyse
if v_Struct = 0
v_r = "0.0.0.0, host : "+p_host+" résolution IP impossible. Vérifier votre paramètre nom ou vos DNS."
wait windows v_r
else
v_Buffer = Repli(Chr(0), HOSTENT_SIZE)
v_IP = Chr(0) + Chr(0) + Chr(0) +Chr(0)
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k109_5731ba5b-a7a5-4883-87cf-543768a29a93.xml.asp
*
DECLARE RtlMoveMemory IN kernel32 STRING @Destination, INTEGER Source, INTEGER Longueur
=RtlMoveMemory(@v_Buffer, v_Struct, HOSTENT_SIZE)
* on s'intéresse donc au octets 13 14 15 et 16
=RtlMoveMemory(@v_ip, b2dword(SubStr(v_Buffer,13,4)), 4)
=RtlMoveMemory(@v_ip, b2dword(v_ip), 4)
* -------------
* retour sous forme de chaine
* -------------
for v_i=1 to 4
v_r = v_r + Alltrim(str(Asc(Substr(v_ip,v_i,1)),3,0))+ Iif(v_i<4,".","")
next
clear dlls RtlMoveMemory
endif
* -------------
* termine l'utilisation de WS2_32
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsacleanup_2.asp
*
DECLARE INTEGER WSACleanup IN ws2_32
=WSACleanup()
clear dlls WSACleanup
clear dlls gethostbyname
endif
clear dlls WSAStartup
return v_r
* -------------
FUNCTION b2dword(p_buffer)
RETURN Asc(substr(p_buffer, 1,1)) + Bitlshift(Asc(substr(p_buffer, 2,1)),8) + Bitlshift(Asc(substr(p_buffer, 3,1)),16) + Bitlshift(Asc(substr(p_buffer, 4,1)),24)
* -------------
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Déconnexion avec winsock [ par CyberPunk2020 ]
Bonjour, En utilisant le composant winsock comme pour une application de chat, je rencontre un probleme à la déconnexion du client comme du serveur.
Problème changer la résolution d'un fichier Tiff [ par sabine2 ]
Bonjour,Avec le ReportListener de Foxpro 9, j'ai créé un fichier Tiff multi-page en prenant le code fourni par l'aide de Foxpro 9.Cependant la résolut
reseau vpn [ par panterga ]
BonjourJ'utilise VFP9 , le logiciel fonctionne en réseau, J'ai installé le .exe et les dll sur un PC client et la base de données et ses fichiers sur
|
Derniers Blogs
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 TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOURTECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOUR par ROMELARD Fabrice
Après un retour sur l'histoire des TechDays de Paris et le fait que ce soit le plus gros event MS au monde (du fait de sa gratuité), le président de MS France (Eric Boustoullier) a fait une présentation de la vision Microsoft pour les années à venir...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
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
|