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
TFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICESTFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICES par vfabing
Afin de s'assurer du bon fonctionnement des différentes synchronisations effectuées par les TFS Integration Tools, 2 rapports sont présents dès l'installation. Il suffit alors d'effectuer les manipulations suivantes pour pouvoir les visualiser : Loca...
Cliquez pour lire la suite de l'article par vfabing CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|