Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: danielajordana en 10 Diciembre 2007, 07:05 am



Título: Instruccion para recuperar el nombre del equipo
Publicado por: danielajordana en 10 Diciembre 2007, 07:05 am
 ::) :)
Con que instruccion puedo recuperar el nombre de equipo de la computadora con la que estoy trabajando. Ya que esté, lo quiero insertar en un tabla que se llama Maquina. para llevar un control de varias maquinas, e identificarlas por el nombre de equipo.
O si saben como recuperar la Direccion Ip para identificarlas por está.


Título: Re: Instruccion para recuperar el nombre del equipo
Publicado por: SKL (orignal) en 10 Diciembre 2007, 09:25 am
podes usar el mismo winsock para eso...

Código:
msgbox WS.LocalHost
msgbox WS.LocalIP

y listo... ahi te dice la ip y el nombre del host

pero por las dudas te dejo el api para saber el nombre de la pc

Código
  1. 'example by Donavon Kuhn (Donavon.Kuhn@Nextel.com)
  2. Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
  3. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  4. Private Sub Form_Load()
  5.    Dim dwLen As Long
  6.    Dim strString As String
  7.    'Create a buffer
  8.    dwLen = MAX_COMPUTERNAME_LENGTH + 1
  9.    strString = String(dwLen, "X")
  10.    'Get the computer name
  11.    GetComputerName strString, dwLen
  12.    'get only the actual data
  13.    strString = Left(strString, dwLen)
  14.    'Show the computer name
  15.    MsgBox strString
  16. End Sub

directo del APIGuide

y para la ip... tambien del apiguide...


esto en el form:
Código
  1. 'This project requires the following components:
  2. ' - a form (Form1) with a textbox (Text1, Multiline=True)
  3. '   and a command button (Command1)
  4. ' - a module (Module1)
  5.  
  6.  
  7. Private Sub Command1_Click()
  8.    Module1.Start
  9. End Sub


Esto en un modulo:
Código
  1. '******************************************************************
  2. 'Created By Verburgh Peter.
  3. ' 07-23-2001
  4. ' verburgh.peter@skynet.be
  5. '-------------------------------------
  6. 'With this small application , you can detect the IP's installed on your computer,
  7. 'including subnet mask , BroadcastAddr..
  8. '
  9. 'I've wrote this because i've a programm that uses the winsock control, but,
  10. 'if you have multiple ip's  installed on your pc , you could get by using the Listen
  11. ' method the wrong ip ...
  12. 'Because Winsock.Localip => detects the default ip installed on your PC ,
  13. ' and in most of the cases it could be the LAN (nic) not the WAN (nic)
  14. 'So then you have to use the Bind function ,to bind to your right ip..
  15. 'but how do you know & find that ip ?
  16. 'you can find it now by this appl.. it check's in the api.. IP Table..
  17. '******************************************************************
  18.  
  19.  
  20. Const MAX_IP = 5   'To make a buffer... i dont think you have more than 5 ip on your pc..
  21.  
  22. Type IPINFO
  23.     dwAddr As Long   ' IP address
  24.    dwIndex As Long '  interface index
  25.    dwMask As Long ' subnet mask
  26.    dwBCastAddr As Long ' broadcast address
  27.    dwReasmSize  As Long ' assembly size
  28.    unused1 As Integer ' not currently used
  29.    unused2 As Integer '; not currently used
  30. End Type
  31.  
  32. Type MIB_IPADDRTABLE
  33.    dEntrys As Long   'number of entries in the table
  34.    mIPInfo(MAX_IP) As IPINFO  'array of IP address entries
  35. End Type
  36.  
  37. Type IP_Array
  38.    mBuffer As MIB_IPADDRTABLE
  39.    BufferLen As Long
  40. End Type
  41.  
  42. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  43. Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
  44. Sub main()
  45. Form1.Show
  46. End Sub
  47.  
  48. 'converts a Long  to a string
  49. Public Function ConvertAddressToString(longAddr As Long) As String
  50.    Dim myByte(3) As Byte
  51.    Dim Cnt As Long
  52.    CopyMemory myByte(0), longAddr, 4
  53.    For Cnt = 0 To 3
  54.        ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
  55.    Next Cnt
  56.    ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
  57. End Function
  58.  
  59. Public Sub Start()
  60. Dim Ret As Long, Tel As Long
  61. Dim bBytes() As Byte
  62. Dim Listing As MIB_IPADDRTABLE
  63.  
  64. Form1.Text1 = ""
  65.  
  66. On Error GoTo END1
  67.    GetIpAddrTable ByVal 0&, Ret, True
  68.  
  69.    If Ret <= 0 Then Exit Sub
  70.    ReDim bBytes(0 To Ret - 1) As Byte
  71.    'retrieve the data
  72.    GetIpAddrTable bBytes(0), Ret, False
  73.  
  74.    'Get the first 4 bytes to get the entry's.. ip installed
  75.    CopyMemory Listing.dEntrys, bBytes(0), 4
  76.    'MsgBox "IP's found : " & Listing.dEntrys    => Founded ip installed on your PC..
  77.    Form1.Text1 = Listing.dEntrys & "   IP addresses found on your PC !!" & vbCrLf
  78.    Form1.Text1 = Form1.Text1 & "----------------------------------------" & vbCrLf
  79.    For Tel = 0 To Listing.dEntrys - 1
  80.        'Copy whole structure to Listing..
  81.       ' MsgBox bBytes(tel) & "."
  82.        CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
  83.         Form1.Text1 = Form1.Text1 & "IP address                   : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
  84.         Form1.Text1 = Form1.Text1 & "IP Subnetmask            : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
  85.         Form1.Text1 = Form1.Text1 & "BroadCast IP address  : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
  86.         Form1.Text1 = Form1.Text1 & "**************************************" & vbCrLf
  87.    Next
  88.  
  89. 'MsgBox ConvertAddressToString(Listing.mIPInfo(1).dwAddr)
  90. Exit Sub
  91. END1:
  92. MsgBox "ERROR"
  93. End Sub


saluditos... http://foro.classicvisualbasic.com