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
[WP7] AJOUTER DES IMAGES DANS LA MEDIA LIBRARY D'UN WINDOWS PHONE 7[WP7] AJOUTER DES IMAGES DANS LA MEDIA LIBRARY D'UN WINDOWS PHONE 7 par Audrey
L'émulateur Windows Phone 7, fourni avec la version Beta des outils développeurs n'inclut aucune image dans sa bibliothèque. Pas très pratique de tester son application lorsque l'on souhaite que l'utilisateur puisse choisir une image présente dans le télé...
Cliquez pour lire la suite de l'article par Audrey VIVE LES MOCKS ET LES POCOSVIVE LES MOCKS ET LES POCOS par vLabz
J'observe régulièrement autour de moi de la confusion à propos de ces deux termes et j'aimerais juste rappeler ce qu'ils signifient. Je ne suis bien sûr pas le mieux placé pour faire une leçon mais je vais faire de mon mieux pour mettre en valeur ce q...
Cliquez pour lire la suite de l'article par vLabz [WF4] WORKFLOW AND CUSTOM ACTIVITIES - BEST PRACTICES (4/5)[WF4] WORKFLOW AND CUSTOM ACTIVITIES - BEST PRACTICES (4/5) par JeremyJeanson
Vendredi dernier Microsoft a publié le quatrième épisode des bonnes pratiques pour coder ses activités custom dans WF4 : endpoint.tv - Workflow and Custom Activities - Best Practices (Part 4) . Tout comme pour les précédents épisodes, j'ai pris le temps d...
Cliquez pour lire la suite de l'article par JeremyJeanson DéVELOPPEMENT MOBILE : .NET COMPACT FRAMEWORK & LIMITATIONSDéVELOPPEMENT MOBILE : .NET COMPACT FRAMEWORK & LIMITATIONS par Pi-R
Introduction :
Le développement d'applications mobiles est quelque peu différent du développement d'applications sous Windows. En effet, le développement d'applications mobiles se base sur le .NET Compact Fra...
Cliquez pour lire la suite de l'article par Pi-R IPHONE VERSUS WP7 CODINGIPHONE VERSUS WP7 CODING par Nicolas
Je relais une présentation sur slideshare.net, qui compare le développement sur Iphone et Windows Phone 7, qui ma fait sourire. I phone versus windows phone 7 coding View more presentations from www.donburnett.com. J'aurais bien aimé une comparai...
Cliquez pour lire la suite de l'article par Nicolas
Logiciels
Xilisoft HD Vidéo Convertisseur 6 (6.0.3.0421)XILISOFT HD VIDéO CONVERTISSEUR 6 (6.0.3.0421)Xilisoft HD Vidéo Convertisseur est un outil professionnel de conversion HDTV, conçu pour transfo... Cliquez pour télécharger Xilisoft HD Vidéo Convertisseur 6 Xilisoft MP4 Convertisseur 6 (6.0.2.0415)XILISOFT MP4 CONVERTISSEUR 6 (6.0.2.0415)Xilisoft MP4 Convertisseur est un outil puissant pour la conversion de vidéo MP4, qui peut conver... Cliquez pour télécharger Xilisoft MP4 Convertisseur 6 Vade Retro Desktop (3.03)VADE RETRO DESKTOP (3.03)Le logiciel antispam Vade Retro pour Microsoft Outlook®, Outlook Express® et Windows Mail®(Vista)... Cliquez pour télécharger Vade Retro Desktop Malwarebytes Anti Malwares (1.46)MALWAREBYTES ANTI MALWARES (1.46)Malwarebytes' Anti-Malware est un anti-malware qui peut éliminer même les plus avancés des logic... Cliquez pour télécharger Malwarebytes Anti Malwares
|