Sign in to follow this  
Followers 0
mithandir1

Need help detecting IP conflicts

5 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

You don't need to use "Call", and you don't need to use @ComSpec.

Share this post


Link to post
Share on other sites

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?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0