Jump to content

Need help detecting IP conflicts


Recommended Posts

I have written a script that assigns IP addresses to a workstation. It picks a random IP address and pings it. If there is no response it assumes that IP is available and assigns it to the workstation. The issue I have is that occasionally It will determine that an IP address is available when it is not, creating an IP conflict.

What I need to know is how to let the script know that there is an IP conflict so that it will automatically assign a new IP.

Here is the code for my script.

while 1

$octet = Random(2, 254,1)
$ping = ping("206.23.108." & $octet, 5000)
if $ping = 0 Then
    call("change")
EndIf
wend

func change()
    Run(@ComSpec & " /c " & 'netsh interface ip set address name="Local Area Connection" static 206.23.108.' & $octet & ' 255.255.255.0 206.23.108.1 1', "", "")

    MsgBox(1,"done", $octet)
    exit
    endfunc
Link to comment
Share on other sites

Try this:

$ping = 1
while $ping <> 0

    $octet = Random(2, 254,1)
    $ping = ping("206.23.108." & $octet, 5000)
    if $ping = 0 Then
        call("change")
    EndIf
wend

func change()
    Run(@ComSpec & " /c " & 'netsh interface ip set address name="Local Area Connection" static 206.23.108.' & $octet & ' 255.255.255.0 206.23.108.1 1', "", "")

    MsgBox(1,"done", $octet)
    exit
endfunc

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Developers

I have written a script that assigns IP addresses to a workstation. It picks a random IP address and pings it. If there is no response it assumes that IP is available and assigns it to the workstation. The issue I have is that occasionally It will determine that an IP address is available when it is not, creating an IP conflict.

What is the Ipaddress of the PC when the script starts?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

EDIT: I figured out a way to do what I wanted. Her is the script in case anyone comes across this post looking for something similar.

#include <Inet.au3>
$octet = 0
call ("octet")

func octet()
while 1=1

$octet = Random(2, 254,1)
$ping = ping("206.23.108." & $octet, 5000)
if $ping = 0 Then
call("change")
EndIf
wend
endfunc
func change()
    Run(@ComSpec & " /c " & 'netsh interface ip set address name="Local Area Connection" static 206.23.108.' & $octet & ' 255.255.255.0 206.23.108.1 1', "", "")
sleep(4000)
$IP = _GetIP()

Select
    case $IP = -1
        call("octet")
    case $IP <> -1
        MsgBox(1, "New Ip Assigned", "206.23.108." & $octet)
        exit
EndSelect
    endfunc
Edited by mithandir1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...