Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi How to config
CSS
IPv4 Address 
  Subnet Mask  
  Default Gateway 


through asp.net in vb codings,
i mean need to 3 input for ip,subnet and default gateway in 3 textbox,if click button need to update in server ip config.


Note:if try to change form client pc or server pc itslef.


Regards
Aravind
Posted

1 solution

Hi
i solved myself,but i face another problem,ip,subnet and default gateway successfully changed,but DHCP is changed to 'No'

below is my code chnage ip,subnet and default gateway

VB
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        
        Dim IPAddress As String = TxtNumIP.Text.Trim '192.168.1.6
        Dim SubnetMask As String = TxtSubnet.Text.Trim '255.255.255.0
        Dim Gateway As String = TxtGateway.Text.Trim  '192.168.1.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
                Dim objdhcp As ManagementBaseObject = Nothing

                objNewIP = objMO.GetMethodParameters("EnableStatic")
                objNewGate = objMO.GetMethodParameters("SetGateways")

                'Set DefaultGateway
                objNewGate("DefaultIPGateway") = New String() {Gateway}
                objNewGate("GatewayCostMetric") = New Integer() {1}

                'Set IPAddress and Subnet Mask
                objNewIP("IPAddress") = New String() {IPAddress}
                objNewIP("SubnetMask") = New String() {SubnetMask}

                objSetIP = objMO.InvokeMethod("EnableStatic", objNewIP, Nothing)
                objSetIP = objMO.InvokeMethod("SetGateways", objNewGate, Nothing)

                ' Console.WriteLine("Updated IPAddress, SubnetMask and Default Gateway!")

            Catch ex As Exception
                ' MessageBox.Show("Unable to Set IP : " & ex.Message)
            End Try
        Next objMO
    End Sub



pls tell me how give "Yes" for DHCP with above coding


Regards
Aravind
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900