منتدى ليبياأرس

منتدى ليبياأرس (http://www.libyars.com/lrs/index.php)
-   لغات البرمجة (http://www.libyars.com/lrs/forumdisplay.php?f=37)
-   -   كود لتغير الايبي (http://www.libyars.com/lrs/showthread.php?t=4286)

عبسي الحمديني 2011-09-04 07:51 AM

كود لتغير الايبي
 

كود PHP:

Private Sub SetIP(ByVal IPAddress As String, ByVal SubnetMask As String, _
                  ByVal Gateway 
As String)
 
    
Dim managementClass As New ManagementClass("Win32_NetworkAdapterConfiguration")
    
Dim mgObjCollection As ManagementObjectCollection = managementClass.GetInstances()
 
    For 
Each mgObject As ManagementObject In mgObjCollection
        
If Not CType(mgObject("IPEnabled"), Boolean) Then Continue For
 
        Try
            
Dim objNewIP As ManagementBaseObject = Nothing
            Dim objSetIP 
As ManagementBaseObject = Nothing
            Dim objNewGate 
As ManagementBaseObject = Nothing
 
            objNewIP 
= mgObject.GetMethodParameters("EnableStatic")
            
objNewGate = mgObject.GetMethodParameters("SetGateways")
 
            
' Set the default gateway (decided to declare and initialise
            ' 
variables rather than attempting to initialize the array
            
' while communicating with the WMI.
            Dim tmpStrArray() As String = {Gateway}
 
            objNewGate("DefaultIPGateway") = tmpStrArray
            Dim tmpIntArray() As Integer = {1}
            objNewGate("GatewayCostMetric") = tmpIntArray
 
            ' 
Set the IP address and subnet.
            
tmpStrArray(0) = IPAddress
            objNewIP
("IPAddress") = tmpStrArray
            tmpStrArray
(0) = SubnetMask
            objNewIP
("SubnetMask") = tmpStrArray
 
            objSetIP 
= mgObject.InvokeMethod("EnableStatic", objNewIP, Nothing)
            
objSetIP = mgObject.InvokeMethod("SetGateways", objNewGate, Nothing)
        Catch 
ex As Exception
            MessageBox
.Show("An error occured: " + ex.Message)
         
End Try
    
Next
End Sub
 
 Example Usage
SetIP
("192.168.1.230", "255.255.255.0", "192.168.1.51") 



الساعة الآن 08:59 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd