Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example how to set IPv4Configuration? #10

Open
tetherit opened this issue Jun 27, 2015 · 18 comments
Open

Example how to set IPv4Configuration? #10

tetherit opened this issue Jun 27, 2015 · 18 comments

Comments

@tetherit
Copy link

Specifically it would be great to have an example for how to enable DHCP. I am trying to do mycam.devicemgmt.IPv4Configuration but it says Method not found. Not quite sure which method to use.

@sinchb
Copy link
Contributor

sinchb commented Jul 4, 2015

IPv4Configuration isn't a method defined by onvif. I think this is what you want. BTW, all the operations can find here

@tetherit
Copy link
Author

tetherit commented Jul 4, 2015

Ah, thank you, I am still struggling though, I tried to do this:

>>> from onvif import ONVIFCamera
>>> mycam = ONVIFCamera('192.168.88.11', 80, 'admin', '', '/usr/local/lib/python2.7/site-packages/etc/onvif/wsdl/')
>>> network_interfaces = mycam.devicemgmt.create_type('SetNetworkInterfaces')
>>> network_interfaces.NetworkInterface.IPv4.DHCP = True
>>> network_interfaces.NetworkInterface.IPv4.DHCP
True
>>> mycam.devicemgmt.SetNetworkInterfaces(network_interfaces)
False
>>> # Hmmm, another try...
>>> network_interfaces = mycam.devicemgmt.GetNetworkInterfaces()
>>> network_interfaces[0].IPv4.Config.DHCP = True
>>> network_interfaces[0].IPv4.Config.DHCP
True
>>> mycam.devicemgmt.SetNetworkInterfaces(network_interfaces[0])
False

Any ideas?

EDIT: Just a note, using this Ruby library, https://github.com/jimxl/ruby-onvif-client, I'm able to change to DHCP. Maybe the camera is buggy but would be good to have a workaround and to be able to use it with this Python library :)

@sinchb
Copy link
Contributor

sinchb commented Jul 6, 2015

well, here is an example to set the network interface(page 22).

I think your passed wrong parameter to SetNetworkInterfaces.
this will work?

mycam.devicemgmt.SetNetworkInterfaces(network_interfaces)

@tetherit
Copy link
Author

Hi, sorry for the late reply, that's the first thing I tried, if I do that I get this output:

>>> from onvif import ONVIFCamera
>>> mycam = ONVIFCamera('192.168.88.11', 80, 'admin', '', '/usr/local/lib/python2.7/site-packages/etc/onvif/wsdl/')
>>> network_interfaces = mycam.devicemgmt.GetNetworkInterfaces()
>>> network_interfaces[0].IPv4.Config.DHCP = True
>>> network_interfaces[0].IPv4.Config.DHCP
True
>>> mycam.devicemgmt.SetNetworkInterfaces(network_interfaces)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 28, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Method instance argument after ** must be a mapping, not list```

@sinchb
Copy link
Contributor

sinchb commented Jul 24, 2015

I think you missed one parameter: InterfaceToken, look at this and this(page 22)

@tetherit
Copy link
Author

Doesn't seem to help:

>>> from onvif import ONVIFCamera
>>> mycam = ONVIFCamera('192.168.88.11', 80, 'admin', '', '/usr/local/lib/python2.7/site-packages/etc/onvif/wsdl/')
>>> network_interfaces = mycam.devicemgmt.GetNetworkInterfaces()
>>> network_interfaces[0]['Info']['Name']
Test
>>> network_interfaces[0].IPv4.Config.DHCP = True
>>> mycam.devicemgmt.SetNetworkInterface('Test',  network_interfaces[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 177, in __getattr__
    return self.service_wrapper(getattr(self.ws_client.service, name))
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 299, in __getattr__
    return getattr(port, name)
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 403, in __getattr__
    return getattr(m, name)
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 494, in __getattr__
    return self[name]
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 507, in __getitem__
    raise MethodNotFound, qn
suds.MethodNotFound: Method not found: 'DeviceService.DevicePort.SetNetworkInterface'
>>>
>>>
>>> mycam.devicemgmt.SetNetworkInterface('Test',  network_interfaces)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 177, in __getattr__
    return self.service_wrapper(getattr(self.ws_client.service, name))
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 299, in __getattr__
    return getattr(port, name)
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 403, in __getattr__
    return getattr(m, name)
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 494, in __getattr__
    return self[name]
  File "/usr/local/lib/python2.7/site-packages/suds/client.py", line 507, in __getitem__
    raise MethodNotFound, qn
suds.MethodNotFound: Method not found: 'DeviceService.DevicePort.SetNetworkInterface'

Can you provide an example of something that works for you with one of your cameras?

@sinchb
Copy link
Contributor

sinchb commented Jul 24, 2015

There is no method named "SetNetworkInterface", It is SetNetworkInterfaces

and are you sure that "Test" is the valid interface token you want to configure?

@tetherit
Copy link
Author

That's what network_interfaces[0]['Info']['Name'] returns - according to that document that would be the interface? - it is also the only interface:

>>> network_interfaces
[(NetworkInterface){
   _DeviceEntity = "Token"
   Enabled = True
   Info = 
      (NetworkInterfaceInfo){
         Name = "Test"
         HwAddress = "00:fc:14:0e:00:05"
         MTU = 1500
      }
   Link = 
      (NetworkInterfaceLink){
         AdminSettings = 
            (NetworkInterfaceConnectionSetting){
               AutoNegotiation = True
               Speed = 100
               Duplex = "Full"
            }
         OperSettings = 
            (NetworkInterfaceConnectionSetting){
               AutoNegotiation = True
               Speed = 100
               Duplex = "Full"
            }
         InterfaceType = "0"
      }
   IPv4 = 
      (IPv4NetworkInterface){
         Enabled = True
         Config = 
            (IPv4Configuration){
               DHCP = True
               Manual[] = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  },
               LinkLocal = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  }
               FromDHCP = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  }
            }
      }
 }]

Alright, here's what I see then:

>>> from onvif import ONVIFCamera
>>> mycam = ONVIFCamera('192.168.88.11', 80, 'admin', '', '/usr/local/lib/python2.7/site-packages/etc/onvif/wsdl/')
>>> network_interfaces = mycam.devicemgmt.GetNetworkInterfaces()
>>> network_interfaces[0]['Info']['Name']
Test
>>> network_interfaces[0].IPv4.Config.DHCP = True
>>> mycam.devicemgmt.SetNetworkInterfaces('Test',  network_interfaces[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 28, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Method instance argument after ** must be a mapping, not str
>>>
>>>
>>> mycam.devicemgmt.SetNetworkInterfaces('Test',  network_interfaces)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 28, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Method instance argument after ** must be a mapping, not str

@sinchb
Copy link
Contributor

sinchb commented Jul 27, 2015

well, the way you passed the parameters isn't correct... Please read the onvif doc, and type instance is the recommended.

BTW, I think the value of Token in you configuration is "Token", while "Test" is the value of "info.Name"

@tetherit
Copy link
Author

I can't pass params I got from GetNetworkInterfaces?

>>> network_interfaces[0].__class__
<class suds.sudsobject.NetworkInterface at 0x107c72598>
>>> 
>>> params = mycam.devicemgmt.create_type('SetNetworkInterfaces')
>>> params.__class__
<class suds.sudsobject.SetNetworkInterfaces at 0x10884f460>

Is this different from a type instance?

Also, 'Token' doesn't seem to work either:

>>>  network_interfaces = mycam.devicemgmt.GetNetworkInterfaces()
>>> mycam.devicemgmt.SetNetworkInterfaces('Token',  network_interfaces)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 28, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Method instance argument after ** must be a mapping, not str
>>> mycam.devicemgmt.SetNetworkInterfaces('Token',  network_interfaces[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/onvif/client.py", line 28, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Method instance argument after ** must be a mapping, not str

Do you have a working example of setting networking?

@tetherit
Copy link
Author

OK, I tried to use a type instance, also a no go :(

>>> from onvif import ONVIFCamera
>>> mycam = ONVIFCamera('192.168.88.11', 80, 'admin', '', '/usr/local/lib/python2.7/site-packages/etc/onvif/wsdl/')
>>> params = mycam.devicemgmt.create_type('SetNetworkInterfaces')
>>> params.InterfaceToken = "Token"
>>> params.NetworkInterface.Enabled = True
>>> params.NetworkInterface.IPv4.Enabled = True
>>> params.NetworkInterface.IPv4.DHCP = True
>>> mycam.devicemgmt.SetNetworkInterfaces(params)
False
>>> params.InterfaceToken = "Test"
>>> mycam.devicemgmt.SetNetworkInterfaces(params)
False

Any ideas? - anyway to get more output than just "False"?

@sinchb
Copy link
Contributor

sinchb commented Jul 28, 2015

ehhh... I think your program worked. False is the response of SetNetworkInterfaes from camera. It indicates whether or not a reboot is required after configuration updates. see the response definition of SetNetworkInterfaces

@tetherit
Copy link
Author

Unfortunately not :(

screen shot 2015-07-28 at 11 08 35

No change after reboot either.

@sinchb
Copy link
Contributor

sinchb commented Jul 28, 2015

really strange... well, sorry for that. I will test on my camera tomorrow, and then i'll tell you the result.

@tetherit
Copy link
Author

Thank you :)

@sinchb
Copy link
Contributor

sinchb commented Jul 29, 2015

Here is my result, everything is OK....

In [14]: mycam.devicemgmt.GetNetworkInterfaces()
Out[14]:
[(NetworkInterface){
    _token = "eth0"
    Enabled = True
    Info =
       (NetworkInterfaceInfo){
          Name = "eth0"
          HwAddress = "c4:2f:90:13:11:15"
          MTU = 1500
       }
    Link =
       (NetworkInterfaceLink){
          AdminSettings =
             (NetworkInterfaceConnectionSetting){
                AutoNegotiation = True
                Speed = 100
                Duplex = "Full"
             }
          OperSettings =
             (NetworkInterfaceConnectionSetting){
                AutoNegotiation = True
                Speed = 100
                Duplex = "Full"
             }
          InterfaceType = "0"
       }
    IPv4 =
       (IPv4NetworkInterface){
          Enabled = True
          Config =
             (IPv4Configuration){
                Manual[] =
                   (PrefixedIPv4Address){
                      Address = "192.168.100.173"
                      PrefixLength = 24
                   },
                DHCP = False
             }
       }
    IPv6 =
       (IPv6NetworkInterface){
          Enabled = True
          Config =
             (IPv6Configuration){
                AcceptRouterAdvert = False
                DHCP = "Off"
                LinkLocal[] =
                   (PrefixedIPv6Address){
                      Address = "fe80::c62f:90ff:fe13:1115"
                      PrefixLength = 64
                   },
                FromDHCP[] =
                   (PrefixedIPv6Address){
                      Address = "fe80::c62f:90ff:fe13:1115"
                      PrefixLength = 64
                   },
             }
       }
  }, (NetworkInterface){
    _token = "wlan0"
    Enabled = False
    Info =
       (NetworkInterfaceInfo){
          Name = "wlan0"
          HwAddress = "8c:18:d9:62:ad:4c"
          MTU = 1500
       }
    IPv4 =
       (IPv4NetworkInterface){
          Enabled = True
          Config =
             (IPv4Configuration){
                FromDHCP =
                   (PrefixedIPv4Address){
                      Address = "169.254.38.101"
                      PrefixLength = 16
                   }
                DHCP = True
             }
       }
  }]

In [15]: params = mycam.devicemgmt.create_type('SetNetworkInterfaces')

In [16]: params.InterfaceToken='eth0'

In [17]: params.NetworkInterface.Enabled=True

In [18]: params.NetworkInterface.IPv4.Enabled = True

In [19]: params.NetworkInterface.IPv4.DHCP = True

In [20]: print mycam.devicemgmt.SetNetworkInterfaces(params)
True

In [21]: mycam.devicemgmt.GetNetworkInterfaces()
Out[21]:
[(NetworkInterface){
    _token = "eth0"
    Enabled = True
    Info =
       (NetworkInterfaceInfo){
          Name = "eth0"
          HwAddress = "c4:2f:90:13:11:15"
          MTU = 1500
       }
    Link =
       (NetworkInterfaceLink){
          AdminSettings =
             (NetworkInterfaceConnectionSetting){
                AutoNegotiation = True
                Speed = 100
                Duplex = "Full"
             }
          OperSettings =
             (NetworkInterfaceConnectionSetting){
                AutoNegotiation = True
                Speed = 100
                Duplex = "Full"
             }
          InterfaceType = "0"
       }
    IPv4 =
       (IPv4NetworkInterface){
          Enabled = True
          Config =
             (IPv4Configuration){
                FromDHCP =
                   (PrefixedIPv4Address){
                      Address = "192.168.100.173"
                      PrefixLength = 24
                   }
                DHCP = True
             }
       }
    IPv6 =
       (IPv6NetworkInterface){
          Enabled = True
          Config =
             (IPv6Configuration){
                AcceptRouterAdvert = False
                DHCP = "Off"
                LinkLocal[] =
                   (PrefixedIPv6Address){
                      Address = "fe80::c62f:90ff:fe13:1115"
                      PrefixLength = 64
                   },
                FromDHCP[] =
                   (PrefixedIPv6Address){
                      Address = "fe80::c62f:90ff:fe13:1115"
                      PrefixLength = 64
                   },
             }
       }
  }, (NetworkInterface){
    _token = "wlan0"
    Enabled = False
    Info =
       (NetworkInterfaceInfo){
          Name = "wlan0"
          HwAddress = "8c:18:d9:62:ad:4c"
          MTU = 1500
       }
    IPv4 =
       (IPv4NetworkInterface){
          Enabled = True
          Config =
             (IPv4Configuration){
                FromDHCP =
                   (PrefixedIPv4Address){
                      Address = "169.254.38.101"
                      PrefixLength = 16
                   }
                DHCP = True
             }
       }
  }]

what is the camera brand? Maybe you can reset your camera and try again.

@tetherit
Copy link
Author

tetherit commented Sep 16, 2016

This is a Chinese no brand camera, so it is possibly faulty, but the ruby library works, so not sure what it is doing that is different. I tried the above basing it on your example and I get this:

>>> mycam = ONVIFCamera('192.168.88.11', 80, 'admin', '', '/usr/local/wsdl')
>>> mycam.devicemgmt.GetNetworkInterfaces()
WARNING:suds.umx.typed:attribute (DeviceEntity) type, not-found
[(NetworkInterface){
   _DeviceEntity = "Token"
   Enabled = True
   Info = 
      (NetworkInterfaceInfo){
         Name = "Test"
         HwAddress = "00:fc:14:0e:00:05"
         MTU = 1500
      }
   Link = 
      (NetworkInterfaceLink){
         AdminSettings = 
            (NetworkInterfaceConnectionSetting){
               AutoNegotiation = True
               Speed = 100
               Duplex = "Full"
            }
         OperSettings = 
            (NetworkInterfaceConnectionSetting){
               AutoNegotiation = True
               Speed = 100
               Duplex = "Full"
            }
         InterfaceType = "0"
      }
   IPv4 = 
      (IPv4NetworkInterface){
         Enabled = True
         Config = 
            (IPv4Configuration){
               DHCP = False
               Manual[] = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  },
               LinkLocal = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  }
               FromDHCP = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  }
            }
      }
 }]
>>> interfaces = mycam.devicemgmt.GetNetworkInterfaces()
WARNING:suds.umx.typed:attribute (DeviceEntity) type, not-found
>>> params = mycam.devicemgmt.create_type('SetNetworkInterfaces')
>>> params.InterfaceToken='Test'
>>> params.NetworkInterface.Enabled=True
>>> params.NetworkInterface.IPv4.Enabled = True
>>> params.NetworkInterface.IPv4.DHCP = True
>>> print mycam.devicemgmt.SetNetworkInterfaces(params)
False
>>> mycam.devicemgmt.GetNetworkInterfaces()
WARNING:suds.umx.typed:attribute (DeviceEntity) type, not-found
[(NetworkInterface){
   _DeviceEntity = "Token"
   Enabled = True
   Info = 
      (NetworkInterfaceInfo){
         Name = "Test"
         HwAddress = "00:fc:14:0e:00:05"
         MTU = 1500
      }
   Link = 
      (NetworkInterfaceLink){
         AdminSettings = 
            (NetworkInterfaceConnectionSetting){
               AutoNegotiation = True
               Speed = 100
               Duplex = "Full"
            }
         OperSettings = 
            (NetworkInterfaceConnectionSetting){
               AutoNegotiation = True
               Speed = 100
               Duplex = "Full"
            }
         InterfaceType = "0"
      }
   IPv4 = 
      (IPv4NetworkInterface){
         Enabled = True
         Config = 
            (IPv4Configuration){
               DHCP = False
               Manual[] = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  },
               LinkLocal = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  }
               FromDHCP = 
                  (PrefixedIPv4Address){
                     Address = "192.168.88.11"
                     PrefixLength = 23
                  }
            }
      }
 }]

@molobrakos
Copy link

molobrakos commented Aug 26, 2017

(Responding to old thread)
This works for me to change the default IP from 192.168.1.10 to 192.168.1.20 ("Chinese camera" from AliExpress):

mgmt.SetNetworkInterfaces(dict(
    InterfaceToken='eth0',     
    NetworkInterface=dict(     
        IPv4=dict(
            Enabled=True,
            Manual=[dict(
                Address='192.168.1.20',
                PrefixLength=24)],
            DHCP=False)))))

mgmt.GetDeviceInformation() returns

(reply){
   Manufacturer = "H264"
   Model = "50H20L_S39"
   FirmwareVersion = "V4.02.R11.00002520.10010.244000..ONVIF 2.4"
   SerialNumber = "2b874578dfb749b9"
   HardwareId = "00001"
 }

SamyCookie pushed a commit to SamyCookie/python-onvif that referenced this issue Mar 6, 2020
Add support for socks proxy by adding support for zeep Transports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants