02/07/2007, 18:42
|
| | Fecha de Ingreso: abril-2007
Mensajes: 67
Antigüedad: 17 años, 8 meses Puntos: 0 | |
Re: Base de datos con las IP, nombre del ISP y localidad, cómo la ubico? La función principal de búsqueda:
***************************** Public Function ObtenerInfoDelWhoIs(ByVal sWhoIsHost As String, ByVal sIPAddress As String) As String
Dim sResult As String = ""
Dim lPort As Integer = 43
Dim oTcp As Net.Sockets.TcpClient = New Net.Sockets.TcpClient(sWhoIsHost, lPort)
Dim oNetStream As Net.Sockets.NetworkStream = oTcp.GetStream
Dim oBaseStream As IO.BufferedStream = New IO.BufferedStream(oNetStream)
Try
Dim oOutputStream As IO.StreamWriter = New IO.StreamWriter(oBaseStream)
oOutputStream.WriteLine(sIPAddress)
oOutputStream.Flush()
Try
Dim oInputStream As IO.StreamReader = New IO.StreamReader(oBaseStream)
Do While oInputStream.Peek <> -1
sResult = sResult & oInputStream.ReadLine() & vbCrLf
Loop
Catch oEX As Exception
sResult = ""
End Try
Catch oEX As Exception
sResult = ""
End Try
Return sResult
End Function
*****************************
De manera que desde un form, puedo averiguar si una IP está, por ejemplo, en whois.lacnic.net y obtener la información:
Requiere un Button1 y un TextBox1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(BucaEnLacNic(TextBox1.Text))
End Sub
Private Function BucaEnLacNic(ByVal sIPAddress As String) As String
Dim sResult As String = ""
BucaEnLacNic = ObtenerInfoDelWhoIs("whois.lacnic.net", sIPAddress)
End Function
*****************************
Usando un Button2 adicional...
Podemos saber el nombre del servidor: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(BuscarOrg(TextBox1.Text))
End Sub
Public Function BuscarOrg(ByVal sIPAddress As String) As String
Dim sHost As String = BucaEnARIN(sIPAddress)
If sHost = "RIPE Network Coordination Centre" Then
sHost = BucaEnRIPE(sIPAddress)
ElseIf sHost = "Asia Pacific Network Information Centre" Then
sHost = BucaEnAPNIC(sIPAddress)
End If
Return sHost
End Function 'Buca En ARIN Private Function BucaEnARIN(ByVal sIPAddress As String) As String
Dim sResult As String = ""
Dim sWhoIsText As String = ObtenerInfoDelWhoIs("whois.arin.net", sIPAddress)
'
Dim iOrgID As Integer = sWhoIsText.IndexOf("OrgID")
If iOrgID > 14 Then
sResult = sWhoIsText.Substring(14, iOrgID - 14)
Dim iCR As Integer = sResult.IndexOf(Chr(10))
If iCR > 1 Then
sResult = sResult.Substring(0, iCR - 1)
End If
Else
Dim iLastNetPos As Integer = sWhoIsText.LastIndexOf("(NET")
If iLastNetPos > -1 Then
Dim iPrevNetPos As Integer = sWhoIsText.Substring(0, iLastNetPos).LastIndexOf("(NET")
If iPrevNetPos = -1 Then iPrevNetPos = 0
iPrevNetPos = sWhoIsText.Substring(iPrevNetPos, iLastNetPos - iPrevNetPos).LastIndexOf(Chr(10))
If iPrevNetPos = -1 Then iPrevNetPos = 0 Else iPrevNetPos = iPrevNetPos + 1
sResult = sWhoIsText.Substring(iPrevNetPos, iLastNetPos - iPrevNetPos)
iPrevNetPos = sResult.LastIndexOf(Chr(10))
If iPrevNetPos = -1 Then iPrevNetPos = 0 Else iPrevNetPos = iPrevNetPos + 1
sResult = sResult.Substring(iPrevNetPos, sResult.Length - iPrevNetPos)
End If
End If
Return Trim(sResult)
End Function 'Buca En RIPE Private Function BucaEnRIPE(ByVal sIPAddress As String) As String
Dim sResult As String = ""
Dim sWhoIsText As String = ObtenerInfoDelWhoIs("whois.ripe.net", sIPAddress)
'
Dim iOrgID_Start As Integer = sWhoIsText.IndexOf("descr:")
Dim iOrgID_End As Integer = sWhoIsText.IndexOf("country:")
If iOrgID_Start > -1 AndAlso iOrgID_End > -1 Then
sResult = sWhoIsText.Substring(iOrgID_Start + 14, iOrgID_End - (iOrgID_Start + 14))
Dim iCR As Integer = sResult.IndexOf(Chr(10))
If iCR > 1 Then
sResult = sResult.Substring(0, iCR - 1)
End If
End If
Return Trim(sResult)
End Function 'Buca En APNIC Private Function BucaEnAPNIC(ByVal sIPAddress As String) As String
Dim sResult As String = ""
Dim sWhoIsText As String = ObtenerInfoDelWhoIs("whois.apnic.net", sIPAddress)
'
Dim iOrgID_Start As Integer = sWhoIsText.IndexOf("descr:")
Dim iOrgID_End As Integer = sWhoIsText.IndexOf("admin-c:")
If iOrgID_Start > -1 AndAlso iOrgID_End > -1 Then
sResult = sWhoIsText.Substring(iOrgID_Start + 14, iOrgID_End - (iOrgID_Start + 14))
Dim iCR As Integer = sResult.IndexOf(Chr(10))
If iCR > 1 Then
sResult = sResult.Substring(0, iCR - 1)
End If
End If
Return Trim(sResult)
End Function ...cortar el código útil, pegar en un Form, y listo. |