How do I generate an automatic IP (DHCP) in VB.NET

Asked

Viewed 302 times

1

Good afternoon, I would like to know how I can be generating an automatic IP (DHCP) in VB.NET and if you need to generate Mascara, Gateway and automatic DNS as well? Or in this case to use Automatic IP, I would have to use a pattern of Mascara, Gateway and DNS?

  • 1

    Explain what it is to generate an automatic IP. What you need this for?

  • I imagine the OP is referring to DHCP.

  • I am configuring a module and in an example distributed by the manufacturer, it gives me 2 options, 1 that would be a Fixed IP and 2 an IP that their system generates, but I am using these examples to generate my project, but when it comes to generating automatic IP I knew how to do.

  • See if this helps you: http://support.microsoft.com/kb/220874 https://www.youtube.com/watch?v=RUZohsAxPxQ

  • That’s right, DHCP

  • 2

    In this case you need a DHCP service enabled for your network segment, @Felipewalleg. Home routers usually offer the service. Companies may have dedicated servers. In a command window, type ipconfig /all - the DHCP server will be listed as DHCP Server.

  • Okay, I found this. So I have to use this IP? And Mascara, Gateway? I use the ones that came up ?

  • If the module is configured to use an automatic IP, you do not need to implement anything on the VB.NET side; the operating environment will get an IP. information such as mask and gateway is only required for static Ips.

  • That’s what I figured, it’s not a programming problem.

  • That’s right, @bigown.

  • I get it. &#xA;no caso eu forneço por forma de uma função um XML para configura-lo, acredito que eu deixe essa parte de IP em vazio quando for DHCP &#xA;'<tipoLan>DHCP</tipoLan>'&#xA;'<lanIP></lanIP>'&#xA;'<lanMask></lanMask>'&#xA;'<lanGW></lanGW>'&#xA; Assim?

  • 2

    @Felipewalleg It will depend on the implementation, but I would say yes. Good tests!

Show 7 more comments

1 answer

1

A Windows-based computer configured to use DHCP can automatically assign an IP address if a DHCP server is not available. For example, this can occur on a network without a DHCP server or on a network on which a DHCP server is temporarily disabled for maintenance.

The INAN (Internet Assigned Number Authority) reserved the number 169.254.0.0-169.254.255.255 for the APIPA address. As a result, APIPA provides a guaranteed address against conflicts with addresses that can be routed.

After assigning an IP address to the network adapter, the computer can use TCP/IP to communicate with another computer connected to the same local network and also configured for APIPA or having the IP address set manually for the address range 169.254.x. y (where x.y represents the customer’s unique identification) with a 255.255.0.0 subnet mask. Note that the computer cannot communicate with computers on other subnets or with computers that do not use automatic private IP addressing. By default, automatic private IP addressing is enabled.

Maybe you want to disable it in one of the following cases:

  • The network uses routers.

  • The network is connected to the Internet without a NAT server or proxy.

Unless DHCP-related messages are disabled, DHCP messages will notify when switching between DHCP addressing and automatic private IP addressing. If DHCP messages are disabled by accident, it is possible to activate them again by changing the Popupflag value in the following Registry key from 00 to 01:

HKEY_LOCAL_MACHINE System Currentcontrolset Services Vxd DHCP

Please note that you need to restart your computer for the change to take effect. It is also possible to determine whether the computer is using APIPA through the Winipcfg tool in Windows Millennium Edition (Me), Windows 98 or Windows 98 Second Edition (SE): Click Start, Run, type "winipcfg" (no quotes) and click OK. Click More information. If the Auto configuration IP Address box contains an IP address within the range 169.254.x. x, the APIPA address will be enabled. If there is an IP address box, the APIPA address will not be enabled at the moment. In Windows 2000, Windows XP or Windows Server 2003, it is possible to determine whether the computer is using APIPA via the Ipconfig command at the command prompt:

Click Start, then Run, type "cmd" (no quotes) and click OK to open an MS-DOS command line window. Type "ipconfig /all" (no quotes) and press the ENTER key. If the line 'Autoconfiguration Enabled' is "Yes" and 'Autoconfiguration IP Address' is 169.254.x. y (in which x.y represents the exclusive identification of the client), the computer will be using APIPA. If the line 'Autoconfiguration Enabled' is "No", the computer will not be using APIPA. It is possible to disable APIPA addressing using any of the following methods.

You can configure TCP/IP information manually, which also disables DHCP. You can disable APIPA (not DHCP) addressing by editing the Record. You can do this by adding the DWORD Registry entry "Ipautoconfigurationenabled" with a value of 0x0 to the following Registry key for Windows Millennium Edition, Windows98 or Windows 98 Second Edition: HKEY_LOCAL_MACHINE System Currentcontrolset Services Vxd DHCP For Windows 2000, Windows XP and Windows Server 2003, APIPA can be disabled by adding the "Ipautoconfigurationenabled" DWORD Registry entry with a value of 0x0 to the following Registry key:

HKEY_LOCAL_MACHINE System Currentcontrolset Services Tcpip Parameters Interfaces Note The GUID Switch Adapter is a GUID (Unique Global Identifier) for computer LAN adapter.

Specifying a value of 1 for the Ipautoconfigurationenabled DWORD entry will enable the APIPA, which is the default state when this value is omitted from the Record. Examples where APIPA can be useful

Example 1: no previous IP address and no DHCP server

When you boot your Windows-based computer (set to DHCP), three or more "Discover" messages will be broadcast. If a DHCP server does not respond after displaying several Discover messages, the Windows-based computer will assign a Class B (APIPA) address to itself. Then, the Windows-based computer will display an error message to the computer user (considering that it has never assigned an IP address by a DHCP server before). The Windows computer will send a Discover message every three minutes in an attempt to establish communication with a DHCP server.

Example 2: Previous IP address and no DHCP server

The computer checks a DHCP server and if it does not find any, it tries to contact the default gateway. If the default gateway responds, the Windows-based computer will retain the previously granted IP address. However, if the computer does not receive a response from the default gateway or if none is assigned, the APIPA address will be used to assign itself an IP address. An error message is displayed to the user and Discover messages are transmitted every three minutes. When a DHCP server goes online, a message stating that communication has been reestablished with the DHCP server is generated.

Example 3: grant expires and no DHCP server

The Windows-based computer attempts to reinstate IP address granting. If the Windows-based computer does not find a DCHP server, it will assign an IP address to itself after generating an error message. Then the computer will broadcast four Discover messages and every five minutes repeat the entire procedure until a DHCP server is online. Thus, a message is generated stating that the communication has been reestablished with the DHCP server.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.