IP değiştirme Yöntem1: aşağıdaki kodu bir butonun altına yapıştırınız.
Kodu goster VBNET
Dim IPAddress As String = "192.168.0.10" Dim SubnetMask As String = "255.255.255.0" Dim Gateway As String = "192.168.0.1" Dim objMC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration") Dim objMOC As ManagementObjectCollection = objMC.GetInstances() For Each objMO As ManagementObject In objMOC If (Not CBool(objMO("IPEnabled"))) Then Continue For End If Try Dim objNewIP As ManagementBaseObject = Nothing Dim objSetIP As ManagementBaseObject = Nothing Dim objNewGate As ManagementBaseObject = Nothing objNewIP = objMO.GetMethodParameters("EnableStatic") objNewGate = objMO.GetMethodParameters("SetGateways") 'Gateway'i ayarla objNewGate("DefaultIPGateway") = New String() {Gateway} objNewGate("GatewayCostMetric") = New Integer() {1} 'IP Adresi ve Subnet Mask'ı ayarla objNewIP("IPAddress") = New String() {IPAddress} objNewIP("SubnetMask") = New String() {SubnetMask} objSetIP = objMO.InvokeMethod("EnableStatic", objNewIP, Nothing) objSetIP = objMO.InvokeMethod("SetGateways", objNewGate, Nothing) Messagebox.show("Ip adresi güncellendi...") Catch ex As Exception MessageBox.Show("Ip adresi güncellenemedi : " & ex.Message) End Try Next objMO |
IP deÄŸiÅŸtirme Yöntem2: aÅŸağıdaki kodu form main’ e yapıştırın. Burada ip deÄŸiÅŸtirme fonkisyonu yaratılarak herhangibir yerden ip deÄŸiÅŸtirme hedeflenmiÅŸtir.
Kodu goster VBNET
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")
Dim tmpStrArray() As String = {Gateway}
objNewGate("DefaultIPGateway") = tmpStrArray
Dim tmpIntArray() As Integer = {1}
objNewGate("GatewayCostMetric") = tmpIntArray
' IP address and subnet burada güncellenir.
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("Bir hata oluÅŸtu: " + ex.Message)
End Try
Next
-----------------------------------------------------------------------------------------------------------------------------------------
Buton eventinin içine :
SetIP(TextBox1.Text, TextBox2.Text, TextBox3.Text) yada
SetIP("192.168.1.10", "255.255.255.0", "192.168.1.1")
yapıştır. |
IP deÄŸiÅŸtirme Yöntem3: aÅŸağıdaki kodu buton eventi’ne yapıştırın.
Kodu goster VBNET
Shell("netsh interface ip set dns ""Local area connection"" static " &Â "192.168.1.1" & " primary") |