Marook-Online
* 06.Feb.2012, 15:09 UTC+1
Welcome, Guest. Please login or register.
Username:
Password:

News: Back again Wink
Main Menu
  Navigation
   Downloads
     Tools
     Music Discs
     SMF Mods
     Trainer & Patches
     EgoShare Uploader
   Guestbook
   NoPaste
   User Map
   Gallery
  
   Malware Scan
   Hacker Blacklist
   Find Abusemail
Top Downloads
Support Me !
Help me by donating a small amount!



Advanced search

Google


Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read
08-Nov-2007 15:51
Marook
Administrator
*****
Offline Offline

Joined: 01-Jan-2005
Posts: 224


If you need to change the IP,Subnet-Mask,Gateway and DNS-Server you could do this task by using WMI. The code shows how to enable a static adress and also getting an IP with DHCP by calling EnableDHCP()

Code
GeSHi (vb):
  1. Private Sub Form_Load()
  2. Dim lStatus As Long
  3. Dim vMsgBoxStyle As VbMsgBoxStyle
  4.  
  5. lStatus = ChangeIP("192.168.0.5")
  6.  
  7. Select Case lStatus
  8.    Case 0, 1
  9.        vMsgBoxStyle = vbInformation
  10.    Case Else
  11.        vMsgBoxStyle = vbCritical
  12. End Select
  13.  
  14. MsgBox GetStatus(lStatus), vMsgBoxStyle
  15.  
  16. End Sub
  17. Private Function ChangeIP(ByVal sNewIP As String, _
  18.  Optional ByVal sGateway As String = "192.168.0.254", _
  19.  Optional ByVal sDNSServer As String = "192.168.0.254", _
  20.  Optional ByVal sSubNetMask As String = "255.255.255.0") As Long
  21.  
  22.  Dim oWMI As Object
  23.  Dim oResult As Object
  24.  Dim oCard As Object
  25.  Dim nStatus As Long
  26.  
  27.  Set oWMI = GetObject("winmgmts:")
  28.  Set oResult = oWMI.execquery("SELECT * FROM win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
  29.  
  30.  For Each oCard In oResult
  31.    With oCard
  32.      If IsArray(.IPAddress) Then
  33.         ChangeIP = .EnableStatic(Array(sNewIP), Array(sSubNetMask))
  34.         .SetGateways Array(sGateway)
  35.         'If you want to set the MTU uncomment the following line
  36.         '.SetMTU Array("1500")
  37.         .SetDNSServerSearchOrder Array(sDNSServer)
  38.      End If
  39.    End With
  40.  Next
  41. End Function
  42. Private Function EnableDHCP() As Long
  43.  Dim oWMI As Object
  44.  Dim oResult As Object
  45.  Dim oCard As Object
  46.  Dim nStatus As Long
  47.  
  48.  Set oWMI = GetObject("winmgmts:")
  49.  Set oResult = oWMI.execquery("SELECT * FROM win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
  50.  
  51.  For Each oCard In oResult
  52.    With oCard
  53.      If IsArray(.IPAddress) Then
  54.            EnableDHCP = .EnableDHCP
  55.        End If
  56.    End With
  57.  Next
  58. End Function
  59. Private Function GetStatus(lStatus As Long) As String
  60. Select Case lStatus
  61.    Case 0
  62.        GetStatus = "Successful completion, no reboot required."
  63.    Case 1
  64.        GetStatus = "Successful completion, reboot required."
  65.    Case 64
  66.        GetStatus = "Method not supported on this platform."
  67.    Case 65
  68.        GetStatus = "Unknown failure."
  69.    Case 66
  70.        GetStatus = "Invalid subnet mask."
  71.    Case 67
  72.        GetStatus = "An error occurred while processing an instance that was returned."
  73.    Case 68
  74.        GetStatus = "Invalid input parameter."
  75.    Case 69
  76.        GetStatus = "More than five gateways specified."
  77.    Case 70
  78.        GetStatus = "Invalid IP address."
  79.    Case 71
  80.        GetStatus = "Invalid gateway IP address."
  81.    Case 72
  82.        GetStatus = "An error occurred while accessing the registry for the requested information."
  83.    Case 73
  84.        GetStatus = "Invalid domain name."
  85.    Case 74
  86.        GetStatus = "Invalid host name."
  87.    Case 75
  88.        GetStatus = "No primary or secondary WINS server defined."
  89.    Case 76
  90.        GetStatus = "Invalid file."
  91.    Case 77
  92.        GetStatus = "Invalid system path."
  93.    Case 78
  94.        GetStatus = "File copy failed."
  95.    Case 79
  96.        GetStatus = "Invalid security parameter."
  97.    Case 80
  98.        GetStatus = "Unable to configure TCP/IP service."
  99.    Case 81
  100.        GetStatus = "Unable to configure DHCP service."
  101.    Case 82
  102.        GetStatus = "Unable to renew DHCP lease."
  103.    Case 83
  104.        GetStatus = "Unable to release DHCP lease."
  105.    Case 84
  106.        GetStatus = "IP not enabled on adapter."
  107.    Case 85
  108.        GetStatus = "IPX not enabled on adapter."
  109.    Case 86
  110.        GetStatus = "Frame or network number bounds error."
  111.    Case 87
  112.        GetStatus = "Invalid frame type."
  113.    Case 88
  114.        GetStatus = "Invalid network number."
  115.    Case 89
  116.        GetStatus = "Duplicate network number."
  117.    Case 90
  118.        GetStatus = "Parameter out of bounds."
  119.    Case 91
  120.        GetStatus = "Access denied."
  121.    Case 92
  122.        GetStatus = "Out of memory."
  123.    Case 93
  124.        GetStatus = "Already exists."
  125.    Case 94
  126.        GetStatus = "Path, file, or object not found."
  127.    Case 95
  128.        GetStatus = "Unable to notify service."
  129.    Case 96
  130.        GetStatus = "Unable to notify DNS service."
  131.    Case 97
  132.        GetStatus = "Interface not configurable."
  133.    Case 98
  134.        GetStatus = "Not all DHCP leases could be released or renewed."
  135.    Case 100
  136.        GetStatus = "DHCP not enabled on adapter."
  137. End Select
  138. End Function
  139.  
Created by GeSHI 1.0.7.20
Logged
 

Pages: [1]   Go Up
Jump to:  

Theme by webtechnica.net

MHD v2.1 © 2oo8 by Marook
32116 hacking attempts defended!