Monday, December 2, 2013
Script Proxy Configuration Network by Terminal on Mac OSX
Posted by
Unknown
#!/bin/bash
#------ Script Proxy Configuration Network by Terminal on Mac OSX
PROXY_SERVER="serverAddress"
PORT=8080
USER="userId"
PASSWORD="Password"
NETWORK=
TURN=1
ALL_NET=$(networksetup -listnetworkserviceorder)
echo "====================================="
echo "List of network services :"
echo "-------------------------------------"
echo $ALL_NET
echo "====================================="
echo "Proxy server : $PROXY_SERVER"
echo "-------------------------------------"
echo "1.Turn on proxy with Wi-Fi Service"
echo "2.Turn off porxy with Wi-Fi Server"
echo "3.Turn on proxy with Ethernet Service"
echo "4.Turn off proxy with Ethernet Service"
echo "0 or other key to exit program !"
echo "-------------------------------------"
read choice
echo "-------------------------------------"
case $choice in
1)
NETWORK=Wi-Fi
;;
2)
NETWORK=Wi-Fi
TURN=0
;;
3)
NETWORK=Ethernet
;;
4)
NETWORK=Ethernet
TURN=0
;;
*)
echo "Exit program..."
exit 0
;;
esac
if [ $TURN -eq 1 ];then
echo "Turning on proxy $NETWORK..."
sudo networksetup -setwebproxy $NETWORK $PROXY_SERVER $PORT on $USER $PASSWORD
sudo networksetup -setsecurewebproxy $NETWORK $PROXY_SERVER $PORT on $USER $PASSWORD
sudo networksetup -setftpproxy $NETWORK $PROXY_SERVER $PORT on $USER $PASSWORD
echo "Proxy $NETWORK service was turned on !"
else
echo "Turning off proxy $NETWORK..."
sudo networksetup -setwebproxystate $NETWORK off
sudo networksetup -setftpproxystate $NETWORK off
sudo networksetup -setsecurewebproxystate $NETWORK off
echo "Proxy $NETWORK service was turned off !"
fi
exit 0
NAME
networksetup -- configuration tool for network settings in System Prefer-
ences.
SYNOPSIS
networksetup [-listnetworkserviceorder] [-listallnetworkservices]
[-listallhardwareports] [-detectnewhardware]
[-getmacaddress hardwareport] [-getcomputername]
[-setcomputername computername] [-getinfo networkservice]
[-setmanual networkservice ip subnet router]
[-setdhcp networkservice [clientid]]
[-setbootp networkservice]
[-setmanualwithdhcprouter networkservice ip]
[-setv4off networkservice] [-setv6off networkservice]
[-setv6automatic networkservice]
[-setv6manual networkservice address prefixLength router]
[-getdnsservers networkservice]
[-setdnsservers networkservice dns1 [dns2] [...]]
[-getsearchdomains networkservice]
[-setsearchdomains networkservice domain1 [domain2] [...]]
[-create6to4service networkservicename]
[-set6to4automatic networkservice]
[-set6to4manual networkservice relayAddress]
[-getftpproxy networkservice]
[-setftpproxy networkservice domain portnumber authenticated username password]
[-setftpproxystate networkservice on | off]
[-getwebproxy networkservice]
[-setwebproxy networkservice domain portnumber authenticated username password]
[-setwebproxystate networkservice on | off]
[-getsecurewebproxy networkservice]
[-setsecurewebproxy networkservice domain portnumber authenticated username password]
[-setsecurewebproxystate networkservice on | off]
[-getstreamingproxy networkservice]
[-setstreamingproxy networkservice domain portnumber authenticated username password]
[-setstreamingproxystate networkservice on | off]
[-getgopherproxy networkservice]
[-setgopherproxy networkservice domain portnumber authenticated username password]
[-setgopherproxystate networkservice on | off]
[-getsocksfirewallproxy networkservice]
[-setsocksfirewallproxy networkservice domain portnumber authenticated username password]
[-setsocksfirewallproxystate networkservice on | off]
[-getproxybypassdomains networkservice]
[-setproxybypassdomains networkservice domain1 [domain2] [...]]
[-getpassiveftp networkservice]
[-setpassiveftp networkservice on | off]
[-getairportnetwork] [-setairportnetwork network [password]]
[-getairportpower] [-setairportpower on | off]
[-getnetworkserviceenabled networkservice]
[-setnetworkserviceenabled networkservice on | off]
[-createnetworkservice networkservicename hardwareport]
[-renamenetworkservice networkservice newnetworkservicename]
[-duplicatenetworkservice networkservice newnetworkservicename]
[-removenetworkservice networkservice]
[-ordernetworkservices service1 [service2] [service3] [...]]
[-getappletalk networkservice]
[-setappletalk networkservice on | off]
[-getMTU hardwareport] [-setMTU hardwarePort value]
[-listvalidMTUrange hardwareport] [-getmedia hardwareport]
[-setmedia hardwareport subtype [option1] [option2] [...]]
[-listvalidmedia hardwareport]
[-createVLAN name parentdevice tag]
[-deleteVLAN name parentdevice tag] [-listVLANs]
[-listdevicesthatsupportVLAN] [-isBondSupported device]
[-createBond name [device1] [device2] [...]]
[-deleteBond bond] [-addDeviceToBond device bond]
[-removeDeviceFromBond device bond] [-listBonds]
[-showBondStatus bond] [-version] [-help] [-printcommands]
DESCRIPTION
The networksetup command is used to configure network settings typically
configured in the System Preferences application. The networksetup com-
mand requires at least "admin" privileges to run.
A list of flags and their descriptions:
-listnetworkserviceorder
Displays a list of network services in the order they are con-
tacted for a connection, along with the corresponding port and
device for each. An asterisk (*) next to a service means the ser-
vice is inactive.
-listallnetworkservices
Displays a list of all the network services on the server's hard-
ware ports. An asterisk (*) denotes that a network service is
disabled.
-listallhardwareports
Displays list of hardware ports with corresponding device name
and ethernet address.
-detectnewhardware
Detects new network hardware and creates a default network ser-
vice on the hardware.
-getmacaddress hardwareport
Displays ethernet (or AirPort) address for hardwareport or device
specified.
-getcomputername
Displays the computer name.
-setcomputername computername
Sets computer name to . This name is used by AFP
and AppleTalk.
-getinfo networkservice
Displays the IP address, subnet mask, router, and hardware
address for the that you specify.
-setmanual networkservice ip subnet router
Set the TCP/IP configuration for to manual with
IP address set to , Subnet Mask set to , and Router
address set to .
-setdhcp networkservice [clientid]
Use this command to set the TCP/IP configuration for the speci-
fied to use DHCP. The client ID is optional.
Specify "Empty" for [clientid] to clear the DHCP client id.
-setbootp networkservice
Use this command to set the TCP/IP configuration for the speci-
fied to use BOOTP.
-setmanualwithdhcprouter networkservice ip
Use this command to specify a manual IP address to use for DHCP
for the specified .
-setv4off networkservice
Use this command to turn IPv4 off on the specified .
-setv6off networkservice
Use this command to turn IPv6 off on the specified .
-setv6automatic networkservice
Use this command to set IPv6 to get its addresses automatically
for .
-setv6manual ip prefixlength router
Use this command to set IPv6 to get its addresses manually for
. Specify the ip address, the prefix length and
the router.
-getdnsservers networkservice
Displays DNS info for .
-setdnsservers networkservice dns1 [dns2] [...]
Use this command to specify the IP addresses of servers you want
the specified to use to resolve domain names.
You can list any number of servers (replace dns1, dns2, and so on
with the IP addresses of domain name servers). If you want to
clear all DNS entries for the specified network service, type
"empty" in place of the DNS server names.
-getsearchdomains networkservice
Displays Domain Name info for .
-setsearchdomains networkservice domain1 [domain2] [...]
Use this command to designate the search domain for the specified
. You can list any number of search domains
(replace domain1, domain2, and so on with the name of a local
domain). If you want to clear all search domain entries for the
specified network service, type OemptyO in place of the domain
name.
-create6to4service -
Use this command to create a new 6 to 4 service with name
.
-set6to4automatic -
Use this command to set the 6 to 4 service such that it will get
the relay address automatically.
-set6to4manual - -
Use this command to set the 6 to 4 service such that it will get
the relay address manually. Specify the that you
would like to set.
-getftpproxy networkservice
Displays FTP proxy (server, port, enabled value) info for .
-setftpproxy networkservice domain portnumber authenticated username
password
Set FTP proxy for with and . Turns proxy on. Optionally, specify or for
to enable and disable authenticated proxy sup-
port. Specify and if you turn authenticated
proxy support on.
-setftpproxystate networkservice on | off
Set FTP proxy on to either or .
-getwebproxy networkservice
Displays Web proxy (server, port, enabled value) info for .
-setwebproxy networkservice domain portnumber authenticated username
password
Set Web proxy for with and . Turns proxy on. Optionally, specify or for
to enable and disable authenticated proxy sup-
port. Specify and if you turn authenticated
proxy support on.
-setwebproxystate networkservice on | off
Set Web proxy on to either or .
-getsecurewebproxy networkservice
Displays Secure Web proxy (server, port, enabled value) info for
.
-setsecurewebproxy networkservice domain portnumber authenticated
username password
Set Secure Web proxy for with and . Turns proxy on. Optionally, specify or for
to enable and disable authenticated proxy sup-
port. Specify and if you turn authenticated
proxy support on.
-setsecurewebproxystate networkservice on | off
Set SecureWeb proxy on to either or .
-getstreamingproxy networkservice
Displays Streaming proxy (server, port, enabled value) info for
.
-setstreamingproxy networkservice domain portnumber authenticated
username password
Set Streaming proxy for with .
Turns proxy on. Optionally, specify or for to enable and disable authenticated proxy support. Specify
and if you turn authenticated proxy support
on.
-setstreamingproxystate networkservice on | off
Set Streamingproxy on to either or .
-getgopherproxy networkservice
Displays Gopher proxy (server, port, enabled value) info for
.
-setgopherproxy networkservice domain portnumber authenticated username
password
Set Gopher proxy for with and . Turns proxy on. Optionally, specify or for
to enable and disable authenticated proxy sup-
port. Specify and if you turn authenticated
proxy support on.
-setgopherproxystate networkservice on | off
Set Gopher proxy on to either or .
-getsocksfirewallproxy networkservice
Displays SOCKS Firewall proxy (server, port, enabled value) info
for .
-setsocksfirewallproxy networkservice domain portnumber authenticated
username password
Set SOCKS Firewall proxy for with and
. Turns proxy on. Optionally, specify or
for to enable and disable authenticated proxy
support. Specify and if you turn authenti-
cated proxy support on.
-setsocksfirewallproxystate networkservice on | off
Set SOCKS Firewall proxy to either or .
-getproxybypassdomains networkservice
Displays Bypass Domain Names for .
-setproxybypassdomains networkservice domain1 [domain2] [...]
Set the Bypass Domain Name Servers for to
[domain2] [...]. Any number of Domain Name servers can
be specified. Specify "Empty" for to clear all Domain
Name entries.
-getpassiveftp networkservice
Displays whether Passive FTP is on or off for .
-setpassiveftp networkservice on | off
Set Passive FTP to either or .
-setautoproxyurl networkservice url
Set proxy auto-config to url for and enable it.
-getautoproxyurl networkservice
Displays proxy auto-config (url, enabled) info for .
-setsocksfirewallproxystate networkservice on | off
Set SOCKS Firewall proxy to either or .
-getairportnetwork
Displays current AirPort Network.
-setairportnetwork network [password]
Set AirPort Network to using optional [password] if
specified.
-getairportpower
Displays whether AirPort power is on or off.
-setairportpower on | off
Set AirPort power to either or .
-getnetworkserviceenabled networkservice
Displays whether a service is on or off (enabled or disabled).
-setnetworkserviceenabled networkservice on | off
Use this command to turn the specified network service on or off
(enable or disable).
-createnetworkservice networkservicename hardwareport
Create a service named on port .
The new service will be enabled by default.
-renamenetworkservice networkservice newnetworkservicename
Use this command to rename the specified network service to .
-duplicatenetworkservice networkservice newnetworkservicename
Use this command to duplicate an existing network service and rename it to the specified name .
-removenetworkservice networkservice
Use this command to delete a network service .
You cannot use this command to delete the last remaining service
for a hardware port. To do so, you use the -setnetworkserviceen-
abled command.
-ordernetworkservices service1 [service2] [service3] [...]
Use this command to designate the order network services are con-
tacted on the specified hardware port. Name the network you want
contacted first, then the second, and so on. Use "listnetworkser-
viceorder" to view current service order. Note: use quotes around
service names which contain spaces (ie. "Built-in Ethernet").
-getappletalk networkservice
Displays whether AppleTalk is on or off (enabled or disabled) on
.
-setappletalk networkservice on | off
Set AppleTalk to either or (enabled or disabled) on
.
-setMTUAndMediaAutomatically hardwarePort
Set hardwareport or device specified back to automatically set-
ting the MTU and Media.
-getMTU hardwareport
Get the MTU value for hardwareport or device specified.
-setMTU hardwarePort value
Set MTU for hardwareport or device specified.
-listValidMTURange hardwareport
List the valid MTU range for hardwareport or device specified.
-getMedia hardwareport
Show both the current setting for media and the active media on
hardwareport or device specified.
-setMedia hardwareport subtype [option1] [option2] [...]
Set media for hardwareport or device specified to subtype. Spec-
ify optional [option1] and additional options depending on sub-
type. Any number of valid options can be specified.
-listValidMedia hardwareport
List valid media options for hardwareport or device name. Enumer-
ates available subtypes and options per subtype.
-createVLAN name parentdevice tag
Create a VLAN with the name over the parent device and with the tag .
-deleteVLAN name parentdevice tag
Delete the VLAN with the name over the parent device and with the tag .
-listVLANs
List the VLANs that have been created.
-listdevicesthatsupportVLAN
List the devices that support VLANs.
-isBondSupported device
Displays YES if the device can be added to a bond. NO if it can-
not.
-createBond name [device1] [device2] [...]
Create a bond with the user-defined-name name and optionally add
any listed devices if they support bonding.
-deleteBond bond
Delete the bond with the specified device-name.
-addDeviceToBond device bond
Add device to bond.
-removeDeviceFromBond device bond
Remove device from bond.
-listBonds
List of all bonds.
-showBondStatus bond
Display the status of the specified bond.
-version
Displays version of networksetup tool.
-help Displays a list of all the commands available in the Network Set-
up Tool, with explanatory information.
-printcommands
Displays a list of commands with no detail.
EXAMPLES
networksetup -listallnetworkservices
networksetup -setmanual "Built-in Ethernet" 192.168.100.100 255.255.255.0
192.168.100.1
networksetup -setdnsservers "Built-in Ethernet" 192.168.100.100
192.168.100.12
networksetup -setsearchdomains "Built-in Ethernet" company.com corp.com
networksetup -setwebproxy "Built-in Ethernet" proxy.company.com 80
networksetup -setwebproxy "Built-In Ethernet" proxy.company.com 80 On
authusername authpassword
networksetup -duplicatenetworkservice "Built-In Ethernet" "Local LAN"
networksetup -getdnsservers "Built-In Ethernet"
networksetup -setMTU en0 1500
networksetup -setMedia en0 autoselect
networksetup -setMedia en0 100baseTX half-duplex
networksetup -createBond MyBond en0 en1
networksetup -addDeviceToBond en0 bond0
FILES
/usr/sbin/networksetup
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment