Jump to content

Recommended Posts

Posted

How to know the submask ipaddress in autoit?

The most of the time its 255.255.255.0

But it can be different, My question: How to know your broadcast addres?

Why i want?

With the submask i can calucate the broadcast address for my udp broadcast chat system idea.

-jaenster

-jaenster

Posted (edited)

How to know the submask ipaddress in autoit?

The most of the time its 255.255.255.0

But it can be different, My question: How to know your broadcast addres?

Why i want?

With the submask i can calucate the broadcast address for my udp broadcast chat system idea.

-jaenster

wow this took a while for me to find

But 1st goto "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" and find the interface number of your network card there all diffrent

$Submask = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{YOUR NETWORKD CARD INTERFACE}", "DhcpSubnetMask")
MsgBox(0, "Test", "Your Submask is: "&$Submask)
Edited by frostfel
  • Moderators
Posted

Could have tried something like:

Func _SubnetMask()
    Local $iPID, $sHold, $aSRE
    $iPID = Run(@ComSpec & " /c ipconfig", "", @SW_HIDE, 2)
    While 1
        $sHold &= StdoutRead($iPID)
        If @error Then ExitLoop
        If StringInStr($sHold, "Subnet Mask") Then
            $aSRE = StringRegExp($sHold, 'Subnet Mask [\.| ]+: (.*?)\r', 1)
            If IsArray($aSRE) Then Return $aSRE[0]
        EndIf
    WEnd
    Return SetError(1, 0, 0)
EndFunc
As well I suppose.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

  • Moderators
Posted

This one makes more sense.

Func _SubnetMask($strIP = @IPAddress1)
    Local $oWMISvc  = ObjGet("winmgmts:\\" & $strIP & "\root\cimv2")
    Local $colAll = $oWMISvc.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    Local $oAll
    For $oAll In $colAll
        For $iCC = 0 To UBound($oAll.IPSubnet)
            If StringRegExp($oAll.IPSubnet($iCC), "255.\d+\.\d+\.\d+") Then Return $oAll.IPSubnet($iCC)
        Next
    Next
    Return SetError(1, 0, 0)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

  • Moderators
Posted

That one^ works but it's very slow.

It was kind of slow... hows this one for speed?
Func _SubnetMask($strIP = @IPAddress1)
    Local $strEnumKey, $nEnum
    Local $strKey = "HKLM\SYSTEM\CurrentControlSet\" & _
            "Services\Tcpip\Parameters\Interfaces\"
    While 1
        $nEnum += 1
        $strEnumKey = RegEnumKey($strKey, $nEnum)
        If @error <> 0 Then ExitLoop
        If RegRead($strKey & $strEnumKey, "DhcpIPAddress") = $strIP Then
            Return RegRead($strKey & $strEnumKey, "DhcpSubnetMask")
        EndIf
    WEnd
    Return SetError(1, 0, 0)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

  • 5 months later...

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
  • Recently Browsing   0 members

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