begin process at 2010 02 09 17:35:13
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

API-OLE

 > 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

Note :
8,67 / 10 - par 3 personnes
8,67 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :API-OLE Classé sous :dns, winsock, résolution, nom, ip Niveau :Expert Date de création :04/02/2005 Vu :6 668

Auteur : FrancisFaure

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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 du même auteur

LISTER LES ADRESSES IP DE LA MACHINE
ADRESSE IP PUBLIQUE (EXTERNE)
Source avec Zip EXPÉDIER UN EMAIL : VFPWINSOCK / VFPSENDMAIL : EXPÉDITION DE...

 Sources de la même categorie

AUTOMATION DE WORD AVEC VFP par AbaqueInside
LISTER LES ADRESSES IP DE LA MACHINE par FrancisFaure
OUVRIR UN DOCUMENT WORD PAR AUTOMATION ET FAIRE UNE FUSION A... par leissler
[VFP]CLASSE SYSTEMTIME par FredArmoni
Source avec Zip SPLASHSCREEN TYPE ALERTE D'OUTLOOK2003 par FredArmoni

 Sources en rapport avec celle ci

LISTER LES ADRESSES IP DE LA MACHINE par FrancisFaure
ADRESSE IP PUBLIQUE (EXTERNE) par FrancisFaure
Source avec Zip EXPÉDIER UN EMAIL : VFPWINSOCK / VFPSENDMAIL : EXPÉDITION DE... par FrancisFaure

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


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


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,796 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales