vtuls Posted August 27, 2009 Share Posted August 27, 2009 hi all im trying to figure something out here i want to write a script that uses the network for starting updates and some other things. that my parrents keep forgeting to do. sending information over the net as well. so i'm trying to write a script that i can use so that they don't have to. i want to capture my ip adress this i know how ( @ipadress1) but now i want to change the last bit of it in to a broadcast adress 255 example my ip is 192.168.115.11 now i save this in a variable and i want to make it so that i change the adress to: 192.168.115.255 this way i can update all computers at once. >_< a badly written code is better than a unwritten onea good written code is even better.but there is always room for improvement. :) Link to comment Share on other sites More sharing options...
Developers Jos Posted August 27, 2009 Developers Share Posted August 27, 2009 You are not being very clear about what you want to do but anyways: you can use StringInStr() to find the position of the last DOT in the ipaddress and use StringLeft() to retrieve that section. Jos 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 More sharing options...
playlet Posted August 27, 2009 Share Posted August 27, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
Xand3r Posted August 27, 2009 Share Posted August 27, 2009 (edited) here's the right way to do it >_< MsgBox(0 , "" , "Broadcast address example" & @CRLF & _ "192.168.1.1 - 255.255.255.0 : " & BC_ADDR("192.168.1.1" , "255.255.255.0") & @CRLF & _ "192.168.1.1 - 255.0.0.0 : " & BC_ADDR("192.168.1.1" , "255.0.0.0") & @CRLF & _ "192.168.1.1 - 255.255.240.0 : " & BC_ADDR("192.168.1.1" , "255.255.240.0")) MsgBox(0 ,"Broadcast address for @IpAddress1" , GET_BROADCAST(@IPAddress1));for GET_BROADCAST you need to use an ip that is allocated Func GET_BROADCAST($IP) $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & @ComputerName & "\root\cimv2") If Not IsObj($objWMIService) Then Exit $colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") For $objAdapter in $colAdapters If Not ($objAdapter.IPAddress) = " " Then For $i = 0 To UBound($objAdapter.IPAddress)-1 If $objAdapter.IPAddress($i)=$IP Then Return BC_ADDR($objAdapter.IPAddress($i),$objAdapter.IPSubnet($i)) Next EndIf Next Return 0 EndFunc Func BC_ADDR($IP, $MASK) Local $BC="" $IP=StringSplit($IP , ".") $MASK=StringSplit($MASK , ".") If $IP[0]<>4 Then Return SetError(1,0,0) If $MASK[0]<>4 Then Return SetError(2,0,0) For $i=1 To 4 $BC&=BitXOR(BitXOR($MASK[$i],255),BitAND($IP[$i],$MASK[$i]))&"." Next Return StringTrimRight($BC,1) EndFunc p.s.: tcp can't broadcast ... but udp can Edited August 27, 2009 by Xand3r Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now