Last active
August 29, 2015 14:04
-
-
Save SirPilgrims/fd86e211b7bb67447914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/* | |
The problem is that the controller is on the same subnet of the pc where I launch the script. | |
So, I'd like to do the same thing bypassing the proxy. | |
I tried to do something like it, but it doesn't works! | |
*/ | |
//TRY | |
//$controller_login='admin:admin'; | |
$dataNew='{ | |
"installInHw":"true", | |
"name":"Flow1", | |
"node": { | |
"id":"00:00:00:00:00:00:00:00", | |
"type":"OF"}, | |
"ingressPort":"2", | |
"etherType": "0x800", | |
"protocol": "6", | |
"tpDst": "80", | |
"priority":"65535", | |
"actions":["DROP"]}'; | |
//PUT flow | |
$url='http://controller_ip:port?ip/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:00/staticFlow/Flow1'; | |
$curl=curl_init($url); | |
//TRY | |
//curl_setopt($curl, CURLOPT_USERPWD, $controller_login); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); | |
curl_setopt($curl, CURLOPT_POSTFIELDS,$dataNew); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
$result = curl_exec($curl); | |
if (!$result) | |
return false; | |
curl_close($curl); // Seems like good practice | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/*I have to install a flow on a controller passing the parameters using json format, | |
so I thought to use curl command in PHP. This code works well: | |
*/ | |
$proxy_login='user:psw'; | |
$proxy_ip='0.0.0.0'; | |
$proxy_port=8080; | |
$controller_login='admin:admin'; | |
$dataNew='{ | |
"installInHw":"true", | |
"name":"Flow1", | |
"node": { | |
"id":"00:00:00:00:00:00:00:00", | |
"type":"OF"}, | |
"ingressPort":"2", | |
"etherType": "0x800", | |
"protocol": "6", | |
"tpDst": "80", | |
"priority":"65535", | |
"actions":["DROP"]}'; | |
//PUT flow | |
$url='http://controller_ip:port?ip/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:00/staticFlow/Flow1'; | |
$curl=curl_init($url); | |
curl_setopt($curl, CURLOPT_PROXYPORT, $proxy_port); | |
curl_setopt($curl, CURLOPT_PROXY, $proxy_ip); | |
curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxy_login); | |
curl_setopt($curl, CURLOPT_USERPWD, $controller_login); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); | |
curl_setopt($curl, CURLOPT_POSTFIELDS,$dataNew); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
$result = curl_exec($curl); | |
if (!$result) | |
return false; | |
curl_close($curl); // Seems like good practice | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment