of the currently configured network?
Is there a simple applescript to renew the DHCP Lease...
AplpeScript does not have such support. However, AppleScript makes it easy to run shell commands — using do shell script
— so if you can find a way to do this in Terminal then you can run that from AppleScript.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
AppleScript can renew DHCP. But it is not simple. I wrote such a script in 7 years ago and I just fixed now.
-- Created 2016-12-17 by Takaaki Naganoya -- Updated 2023-03-06 by Takaaki Naganoya -- 2016-2023 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation"
set aDevRes to getActiveNetworkInterfaceDeviceName() of me --set aDevList to devName of (first item of aDevRes)
repeat with i in aDevRes set aDev to devName of contents of i log aDev --http://superuser.com/questions/86956/release-renew-ip-address-via-terminal-in-os-x do shell script ("ipconfig set " & quoted form of aDev & " DHCP") with administrator privileges end repeat
--ifconfigからactiveなデバイス名だけをピックアップする on getActiveNetworkInterfaceDeviceName() set aRes to (do shell script "ifconfig") set aList to paragraphs of aRes
set devNameList to {}
repeat with i in aList
set j to contents of i
set bRes to regexMatches(j, "^[^\\t]*") of me
if bRes is not equal to {{""}} then
set the end of devNameList to contents of item 1 of item 1 of bRes
end if
end repeat
--Parse ifconfig results by device name list
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to devNameList --かなりトリッキー
set tmpList to text items of aRes
set AppleScript's text item delimiters to curDelim
--initialize
set bList to rest of tmpList --remove blank item at top
set aCount to 1
set aResList to current application's NSMutableArray's alloc()'s init()
repeat with i in bList
set aCon to contents of i
set aDat to contents of item aCount of devNameList
--Device Name
set aDevName to retStrFromTopToAstr(aDat, ":") of me
set bCon to paragraphs 2 thru -1 of aCon
set cCon to aDat & retDelimedText(bCon, return) of me
--Activeなdeviceを抽出するための条件付け
set activeF1 to cCon contains "status: active"
set activeF2 to cCon does not contain "media: autoselect (<unknown type>)"
set aRec to (current application's NSDictionary's dictionaryWithDictionary:{devName:aDevName, isActive:(activeF1 and activeF2), ifconfigRes:cCon})
(aResList's addObject:aRec)
set aCount to aCount + 1
end repeat
set activeIF to filterRecListByLabel(aResList, "isActive == [c]%@", {true}) of me
return activeIF as list
end getActiveNetworkInterfaceDeviceName
--http://qiita.com/szk-3/items/8bbe841eb0295caee6b0 on regexMatches(aText as text, pattern as text) set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value) set aString to current application's NSString's stringWithString:aText set matches to regularExpression's matchesInString:aString options:0 range:{location:0, |length|:aString's |length|()} set matchResultList to {} repeat with match in matches set mRes to {} repeat with i from 0 to (match's numberOfRanges as integer) - 1 set end of mRes to (aString's substringWithRange:(match's rangeAtIndex:i)) as text end repeat set end of matchResultList to mRes end repeat return matchResultList end regexMatches
--リストを指定デリミタを入れつつテキスト化 on retDelimedText(aList, aDelim) set aText to "" set curDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to aDelim set aText to aList as text set AppleScript's text item delimiters to curDelim return aText end retDelimedText
--先頭から指定キャラクタまでを抽出して返す on retStrFromTopToAstr(aStr, aTarg) set aLen to length of aTarg set anOffset to offset of aTarg in aStr set bStr to text 1 thru (anOffset - aLen) of aStr return bStr end retStrFromTopToAstr
--リストに入れたレコードを、指定の属性ラベルの値で抽出(predicateとパラメータを分離) on filterRecListByLabel(aRecList, aPredicate, aParam) set aArray to current application's NSArray's arrayWithArray:aRecList set aPredicate to current application's NSPredicate's predicateWithFormat:aPredicate argumentArray:aParam set filteredArray to aArray's filteredArrayUsingPredicate:aPredicate set bList to filteredArray as list return bList end filterRecListByLabel
Hmm.. something wrong with my post...
-- Created 2016-12-17 by Takaaki Naganoya
-- Updated 2023-03-06 by Takaaki Naganoya
-- 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set aDevRes to getActiveNetworkInterfaceDeviceName() of me
--set aDevList to devName of (first item of aDevRes)
repeat with i in aDevRes
set aDev to devName of contents of i
log aDev
--http://superuser.com/questions/86956/release-renew-ip-address-via-terminal-in-os-x
do shell script ("ipconfig set " & quoted form of aDev & " DHCP") with administrator privileges
end repeat
--ifconfigからactiveなデバイス名だけをピックアップする
on getActiveNetworkInterfaceDeviceName()
set aRes to (do shell script "ifconfig")
set aList to paragraphs of aRes
set devNameList to {}
repeat with i in aList
set j to contents of i
set bRes to regexMatches(j, "^[^\\t]*") of me
if bRes is not equal to {{""}} then
set the end of devNameList to contents of item 1 of item 1 of bRes
end if
end repeat
--Parse ifconfig results by device name list
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to devNameList --かなりトリッキー
set tmpList to text items of aRes
set AppleScript's text item delimiters to curDelim
--initialize
set bList to rest of tmpList --remove blank item at top
set aCount to 1
set aResList to current application's NSMutableArray's alloc()'s init()
repeat with i in bList
set aCon to contents of i
set aDat to contents of item aCount of devNameList
--Device Name
set aDevName to retStrFromTopToAstr(aDat, ":") of me
set bCon to paragraphs 2 thru -1 of aCon
set cCon to aDat & retDelimedText(bCon, return) of me
--Activeなdeviceを抽出するための条件付け
set activeF1 to cCon contains "status: active"
set activeF2 to cCon does not contain "media: autoselect (<unknown type>)"
set aRec to (current application's NSDictionary's dictionaryWithDictionary:{devName:aDevName, isActive:(activeF1 and activeF2), ifconfigRes:cCon})
(aResList's addObject:aRec)
set aCount to aCount + 1
end repeat
set activeIF to filterRecListByLabel(aResList, "isActive == [c]%@", {true}) of me
return activeIF as list
end getActiveNetworkInterfaceDeviceName
--http://qiita.com/szk-3/items/8bbe841eb0295caee6b0
on regexMatches(aText as text, pattern as text)
set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value)
set aString to current application's NSString's stringWithString:aText
set matches to regularExpression's matchesInString:aString options:0 range:{location:0, |length|:aString's |length|()}
set matchResultList to {}
repeat with match in matches
set mRes to {}
repeat with i from 0 to (match's numberOfRanges as integer) - 1
set end of mRes to (aString's substringWithRange:(match's rangeAtIndex:i)) as text
end repeat
set end of matchResultList to mRes
end repeat
return matchResultList
end regexMatches
--リストを指定デリミタを入れつつテキスト化
on retDelimedText(aList, aDelim)
set aText to ""
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to aDelim
set aText to aList as text
set AppleScript's text item delimiters to curDelim
return aText
end retDelimedText
--先頭から指定キャラクタまでを抽出して返す
on retStrFromTopToAstr(aStr, aTarg)
set aLen to length of aTarg
set anOffset to offset of aTarg in aStr
set bStr to text 1 thru (anOffset - aLen) of aStr
return bStr
end retStrFromTopToAstr
--リストに入れたレコードを、指定の属性ラベルの値で抽出(predicateとパラメータを分離)
on filterRecListByLabel(aRecList, aPredicate, aParam)
set aArray to current application's NSArray's arrayWithArray:aRecList
set aPredicate to current application's NSPredicate's predicateWithFormat:aPredicate argumentArray:aParam
set filteredArray to aArray's filteredArrayUsingPredicate:aPredicate
set bList to filteredArray as list
return bList
end filterRecListByLabel
code-block