Foros del Web » Programando para Internet » ASP Clásico »

Como validar un dominio usando ASP?

Estas en el tema de Como validar un dominio usando ASP? en el foro de ASP Clásico en Foros del Web. Amigos, Tengo una función para ejecutar el comando nslookup y verificar desde ASP si existe un dominio. Es parte de una función que valida el ...
  #1 (permalink)  
Antiguo 04/11/2004, 18:34
Avatar de luisvasquez  
Fecha de Ingreso: diciembre-2003
Ubicación: Venezuela
Mensajes: 879
Antigüedad: 21 años, 5 meses
Puntos: 6
Como validar un dominio usando ASP?

Amigos,

Tengo una función para ejecutar el comando nslookup y verificar desde ASP si existe un dominio. Es parte de una función que valida el correo.

La idea es validar una forma donde el visitante introduce un correo para Recomendar mi sitio, a cambio de una contraseña de acceso temporal.

Pues bien, me atrevo a decir que el 90% de los correos introducidos en la forma pertenecen a dominios como dsdsdsd.com o algo por el estilo.

Esta función pretende validar esto en la forma, pero hasta ahora no lo he podido hacer andar.

En mi Pc local (Windows 2000 Pro con IIS 5) se queda el browser en blanco durante mucho tiempo y al final debo reiniciar el IIS. Puse para seguir donde se queda colgado y es precisamente en la ejecución del comando nslookup (pueden ver la linea en ROJO).

Cuando lo monto en el server, TODOS los dominios aparecen como invalidos...

Podrían darle un vistazo y ayudarme con esto?? creo que al final será util para todos...

Saludos y gracias, Luis Vásquez
<%

Function DomainLookup(sDomain)
Dim sReadData 'As String
Dim fIpIsNextLine 'Ad boolean
'Crear el objeto
set oShell = Server.CreateObject("Wscript.Shell")

'Ejecutar NSLookup via Cmd y poner el resultado en un archivo temporal

oShell.Run "%ComSpec% /c nslookup " & sDomain & " > %Tmp%\" & Session.SessionID & sDomain & ".txt", 0, True

'Abrir el archivo y leer el contenido para buscar la IP, lo cual nos indicará que el dominio EXISTE

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set oText = Fso.OpenTextFile("%Tmp%\" & Session.SessionID & sDomain & ".txt")

Do While Not oText.AtEndOfStream

'Read In the Text Dump
sReadData = Trim(oText.Readline)

'If the domain name was found in the previous line read then this should be the IP.
If fIpIsNextLine then DomainLookup = True

'If the domain name was found in the Read line then the tell it the next line is the Ip.
'If an IP address was not found then it should not return the domain we are looking for in
' the txt file.
If Instr(1, sReadData, sDomain) then fIpIsNextLine = true
Loop

' Cerrar el archivo
oText.Close
' Borrar el archivo
FSO.DeleteFile "%Tmp%" & Session.SessionID & sDomain & ".txt"
Set FSO = Nothing
End Function
%>

Última edición por luisvasquez; 04/11/2004 a las 18:37
  #2 (permalink)  
Antiguo 05/11/2004, 00:08
Avatar de sjam7  
Fecha de Ingreso: diciembre-2001
Ubicación: Guadalajara, Mexico
Mensajes: 3.672
Antigüedad: 23 años, 4 meses
Puntos: 16
y por que no haces esto: le envias un email al que te va a recomendar para validar con un link hacia una pagina donde generes el codigo para la recomendacion, asi si el mail es falso, desde ahi te das cuenta... es mas engorroso para el que te va a recomendar pero a cambio de una clave creo que si vale la pena lo harian
__________________
CreandoWebs.com
www.creandowebs.com
PLANTILLAS TEMPLATEMONSTER CON 10% DE DESCUENTO
  #3 (permalink)  
Antiguo 05/11/2004, 00:44
Avatar de luisvasquez  
Fecha de Ingreso: diciembre-2003
Ubicación: Venezuela
Mensajes: 879
Antigüedad: 21 años, 5 meses
Puntos: 6
Gracias por tu respuesta.

Lo que sucede es que el usuario llega a la "forma", con la finalidad de ganarse su contraseña de acceso. Escribe su email y el email de un amigo, para recomendarle el sitio. A ambos les llega una contraseña de acceso.

El problema está en que el usuario coloca bien su correo, pero en el de el amigo coloca [email protected]. De esta manera, el obtiene una contraseña, pero no está recomendando a alguien.

Había pensado en obligarlo a introducir un correo correcto, enviandole su contraseña al amigo y no a él. de esta manera es el amigo quien le devuelve el email con la contraseña y garantizo que el personaje en cuestión existe.

Sin embargo, y por mi experiencia en la psicología del internauta, el tendrá una cuenta hotmail y una yahoo y se recomendará a el mismo a fin de checar rapidamente el correo y obtener su contraseña.

Lo idel es validar las 3 etapas, pero no creo que pueda usando un hosting compoartido porque hay que instalar algún componente como hexvalidemail .

las 3 etapas son

1 - la sintaxis
2 - la existencia del dominio
3 - la existencia del buzón dentro del dominio

Es posible llegar a la fase 2 sin instalar componentes en el servidor, pero aun no lo he logrado.

Teoricamente se hace ejecutando un comando ms-dos llamado nslookup, que devuelve la ip de un dominio..si el dominio tiene IP, entonces existe...

Espero sus comentarios.
  #4 (permalink)  
Antiguo 05/11/2004, 18:35
Avatar de MrLake  
Fecha de Ingreso: febrero-2003
Ubicación: México
Mensajes: 75
Antigüedad: 22 años, 3 meses
Puntos: 0
De acuerdo

Lo que se me ocurre es que uses la librería wininet.dll tiene todas las funciones de comunicaciones del internet explorer

Si no quieres hacer tu DLL te mando uno pero si lo quieres hacer ...

1.- Crea un DLL con la función Validahttp lo puedes hacer en VB

Declaración de la librería

Option Explicit

Declare Function GetProcessHeap Lib "kernel32" () As Long
Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
Public Const HEAP_ZERO_MEMORY = &H8
Public Const HEAP_GENERATE_EXCEPTIONS = &H4

Declare Sub CopyMemory1 Lib "kernel32" Alias "RtlMoveMemory" ( _
hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Declare Sub CopyMemory2 Lib "kernel32" Alias "RtlMoveMemory" ( _
hpvDest As Long, hpvSource As Any, ByVal cbCopy As Long)

Public Const MAX_PATH = 260
Public Const NO_ERROR = 0
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_OFFLINE = &H1000


Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type


Public Const ERROR_NO_MORE_FILES = 18

Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long

Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _
lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long

Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean

Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean

Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
' Initializes an application's use of the Win32 Internet functions
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

' User agent constant.
Public Const scUserAgent = "vb wininet"

' Use registry access settings.
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_OPEN_TYPE_DIRECT = 1
Public Const INTERNET_OPEN_TYPE_PROXY = 3
Public Const INTERNET_INVALID_PORT_NUMBER = 0

Public Const FTP_TRANSFER_TYPE_BINARY = &H2
Public Const FTP_TRANSFER_TYPE_ASCII = &H1
Public Const INTERNET_FLAG_PASSIVE = &H8000000

'Verifica la conexion
Public Const FLAG_ICC_FORCE_CONNECTION = &H1
Public Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

' Opens a HTTP session for a given site.
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, _
ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Const ERROR_INTERNET_EXTENDED_ERROR = 12003
Public Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" ( _
lpdwError As Long, _
ByVal lpszBuffer As String, _
lpdwBufferLength As Long) As Boolean

' Number of the TCP/IP port on the server to connect to.
Public Const INTERNET_DEFAULT_FTP_PORT = 21
Public Const INTERNET_DEFAULT_GOPHER_PORT = 70
Public Const INTERNET_DEFAULT_HTTP_PORT = 80
Public Const INTERNET_DEFAULT_HTTPS_PORT = 443
Public Const INTERNET_DEFAULT_SOCKS_PORT = 1080

Public Const INTERNET_OPTION_CONNECT_TIMEOUT = 2
Public Const INTERNET_OPTION_RECEIVE_TIMEOUT = 6
Public Const INTERNET_OPTION_SEND_TIMEOUT = 5

Public Const INTERNET_OPTION_USERNAME = 28
Public Const INTERNET_OPTION_PASSWORD = 29
Public Const INTERNET_OPTION_PROXY_USERNAME = 43
Public Const INTERNET_OPTION_PROXY_PASSWORD = 44

' Type of service to access.
Public Const INTERNET_SERVICE_FTP = 1
Public Const INTERNET_SERVICE_GOPHER = 2
Public Const INTERNET_SERVICE_HTTP = 3

' Opens an HTTP request handle.
Public Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" _
(ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As String, ByVal sVersion As String, _
ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

' Brings the data across the wire even if it locally cached.
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Public Const INTERNET_FLAG_MULTIPART = &H200000

Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000

' Sends the specified request to the HTTP server.
Public Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal _
hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal sOptional As _
String, ByVal lOptionalLength As Long) As Integer


' Queries for information about an HTTP request.
Public Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" _
(ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, _
ByRef lBufferLength As Long, ByRef lIndex As Long) As Integer
  #5 (permalink)  
Antiguo 05/11/2004, 18:36
Avatar de MrLake  
Fecha de Ingreso: febrero-2003
Ubicación: México
Mensajes: 75
Antigüedad: 22 años, 3 meses
Puntos: 0
' The possible values for the lInfoLevel parameter include:
Public Const HTTP_QUERY_CONTENT_TYPE = 1
Public Const HTTP_QUERY_CONTENT_LENGTH = 5
Public Const HTTP_QUERY_EXPIRES = 10
Public Const HTTP_QUERY_LAST_MODIFIED = 11
Public Const HTTP_QUERY_PRAGMA = 17
Public Const HTTP_QUERY_VERSION = 18
Public Const HTTP_QUERY_STATUS_CODE = 19
Public Const HTTP_QUERY_STATUS_TEXT = 20
Public Const HTTP_QUERY_RAW_HEADERS = 21
Public Const HTTP_QUERY_RAW_HEADERS_CRLF = 22
Public Const HTTP_QUERY_FORWARDED = 30
Public Const HTTP_QUERY_SERVER = 37
Public Const HTTP_QUERY_USER_AGENT = 39
Public Const HTTP_QUERY_SET_COOKIE = 43
Public Const HTTP_QUERY_REQUEST_METHOD = 45
Public Const HTTP_STATUS_DENIED = 401
Public Const HTTP_STATUS_PROXY_AUTH_REQ = 407

' Add this flag to the about flags to get request header.
Public Const HTTP_QUERY_FLAG_REQUEST_HEADERS = &H80000000
Public Const HTTP_QUERY_FLAG_NUMBER = &H20000000
' Reads data from a handle opened by the HttpOpenRequest function.
Public Declare Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer

Public Declare Function InternetWriteFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal sBuffer As String, _
ByVal lNumberOfBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer

Public Declare Function FtpOpenFile Lib "wininet.dll" Alias _
"FtpOpenFileA" (ByVal hFtpSession As Long, _
ByVal sFileName As String, ByVal lAccess As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
Public Declare Function InternetSetOption Lib "wininet.dll" Alias "InternetSetOptionA" _
(ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByVal lBufferLength As Long) As Integer
Public Declare Function InternetSetOptionStr Lib "wininet.dll" Alias "InternetSetOptionA" _
(ByVal hInternet As Long, ByVal lOption As Long, ByVal sBuffer As String, ByVal lBufferLength As Long) As Integer

' Closes a single Internet handle or a subtree of Internet handles.
Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer

' Queries an Internet option on the specified handle
Public Declare Function InternetQueryOption Lib "wininet.dll" Alias "InternetQueryOptionA" _
(ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long) As Integer

' Returns the version number of Wininet.dll.
Public Const INTERNET_OPTION_VERSION = 40

' Contains the version number of the DLL that contains the Windows Internet
' functions (Wininet.dll). This structure is used when passing the
' INTERNET_OPTION_VERSION flag to the InternetQueryOption function.
Public Type tWinInetDLLVersion
lMajorVersion As Long
lMinorVersion As Long
End Type

' Adds one or more HTTP request headers to the HTTP request handle.
Public Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" _
(ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, _
ByVal lModifiers As Long) As Integer

' Flags to modify the semantics of this function. Can be a combination of these values:

' Adds the header only if it does not already exist; otherwise, an error is returned.
Public Const HTTP_ADDREQ_FLAG_ADD_IF_NEW = &H10000000

' Adds the header if it does not exist. Used with REPLACE.
Public Const HTTP_ADDREQ_FLAG_ADD = &H20000000

' Replaces or removes a header. If the header value is empty and the header is found,
' it is removed. If not empty, the header value is replaced
Public Const HTTP_ADDREQ_FLAG_REPLACE = &H80000000





'
'
'Módulo para el manejo de errores de wininet
'
Declare Function FormatMessage _
Lib "kernel32" Alias "FormatMessageA" _
(ByVal dwFlags As Long, _
lpSource As Any, _
ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, _
ByVal lpBuffer As String, _
ByVal nSize As Long, _
Arguments As Long) As Long
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long


2.- crea esta función


Public Function Validahttp(URL As String) As Integer
Validahttp = 0
'Verifica si existe una direccion de http de internet
'Adrián Lago
If InternetCheckConnection(URL, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
Validahttp = 0
Else
Validahttp = 1
End If

End Function


3. - En el ASP

'Desclaracion del DLL
Set MiDll = Server.CreateObject("Mi_Dll.Utils")

'Correo a validar
Correo = "[email protected]"

'Convertir el correo a dominio
Dominio = "http://www."&mid(Correo ,instr(Correo,"@")+1, len(Correo)-instr(Correo ,"@"))

'Verificar que exista el dominio
dominiovalido = MiDll.Validahttp (Dominio)
if dominiovalido = 1 then
response.write "El dominio " & Dominio & " Es válido"
else
response.write "El dominio " & Dominio & " no existe, verifique que lo ha escrito correctamente"
end if


Espero que te sea de utilidad
  #6 (permalink)  
Antiguo 05/11/2004, 21:47
Avatar de sjam7  
Fecha de Ingreso: diciembre-2001
Ubicación: Guadalajara, Mexico
Mensajes: 3.672
Antigüedad: 23 años, 4 meses
Puntos: 16
y se puede usar ese dll en un hosting contratado o ajeno?
__________________
CreandoWebs.com
www.creandowebs.com
PLANTILLAS TEMPLATEMONSTER CON 10% DE DESCUENTO
  #7 (permalink)  
Antiguo 07/11/2004, 19:38
Avatar de MrLake  
Fecha de Ingreso: febrero-2003
Ubicación: México
Mensajes: 75
Antigüedad: 22 años, 3 meses
Puntos: 0
No estoy seguro, el wininet.dll debe estar instalado si tiene internet explorer, pero no se puede declarar directamente en el asp
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:18.