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
[ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1[ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1 par pierre
Si vous avez téléchargé comme moi Microsoft Forums NNTP Bridge V1 avant le 11 mars 2010 (voir [Astuce] Disponibilité de Microsoft Forum NNTP Bridge Version 1.0), un problème de date localisée pour les non anglais était présent. Un patch est disponibl...
Cliquez pour lire la suite de l'article par pierre PB LORS DE L'INSTALLATION SHAREPOINT 2010.PB LORS DE L'INSTALLATION SHAREPOINT 2010. par Patrick Guimonet
Lors de l'installation de SharePoint 2010, j'ai rencontré un problème de plantage à l'étape 5 du configuration Wizard. Ca se termine sur cet écran : Et en analysant le fichier de journalisation, on remarque vers la fin des 15000 et quelques lign...
Cliquez pour lire la suite de l'article par Patrick Guimonet [WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (2/2)[WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (2/2) par JeremyJeanson
Après mon précédent article qui attaque les contraintes par la fasse Nord de l'Everest. passons à la seconde possibilité offerte par WF4 pour valider une activité : la metadata . Je vous en ai déjà toucher un ou deux mots. La metadata dans WF4 est un élém...
Cliquez pour lire la suite de l'article par JeremyJeanson [WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (1/2)[WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (1/2) par JeremyJeanson
De WF3 à WF4 pas mal de choses on été changées pour faciliter la vie des développeurs, mais certain points peuvent sembler obscures. comme les contraintes. Pour vous guider, je me lance dans une série de deux articles. Ils présenterons deux approches poss...
Cliquez pour lire la suite de l'article par JeremyJeanson [ASP.NET] NE PAS SE FAIRE AVOIR PAR IHTTPMODULE ET SA MéTHODE INIT()[ASP.NET] NE PAS SE FAIRE AVOIR PAR IHTTPMODULE ET SA MéTHODE INIT() par tja
Beaucoup de développeurs pensent que lorsqu'on créé et enregistre un IHttpModule, il n'en existe qu'une seule instance et la méthode Init() sera appelée qu'une fois.
C'est faux
Cela peut vraiment créer des bugs subtils dont en ne se rend pas compte ...
Cliquez pour lire la suite de l'article par tja
Forum
RE : TXT VERS DBFRE : TXT VERS DBF par MichelAtoutFox
Cliquez pour lire la suite par MichelAtoutFox RE : TXT VERS DBFRE : TXT VERS DBF par MichelAtoutFox
Cliquez pour lire la suite par MichelAtoutFox
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|