change_ip_utility.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # @file change_ip_utility.cc
4 #
5 # Copyright 2013-2025
6 # Carnegie Robotics, LLC
7 # 4501 Hatfield Street, Pittsburgh, PA 15201
8 # http://www.carnegierobotics.com
9 #
10 # All rights reserved.
11 #
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions are met:
14 # * Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # * Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # * Neither the name of the Carnegie Robotics, LLC nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL CARNEGIE ROBOTICS, LLC BE LIABLE FOR ANY
27 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 # Significant history (date, user, job code, action):
35 # 2025-04-07, malvarado@carnegierobotics.com, IRAD, Created file.
36 #
37 
38 import argparse
39 import os
40 
41 import libmultisense as lms
42 
43 
44 def main(args):
45  channel_config = lms.ChannelConfig()
46  channel_config.ip_address = args.current_ip_address
47  channel_config.connect_on_initialization = (args.interface is None)
48 
49  with lms.Channel.create(channel_config) as channel:
50  if not channel:
51  print("Invalid channel")
52  exit(1)
53 
54  if not args.disable_confirmation:
55  print(f"NEW address {args.new_ip_address}")
56  print(f"NEW gateway {args.new_gateway}")
57  print(f"NEW netmask {args.new_netmask}")
58 
59  if args.interface is not None:
60  print(f"** WARNING: All MultiSense devices attached to the interface {args.interface} "
61  "will have their IPs changed **")
62 
63  res = input("Really update network configuration? (y/n):")[0]
64  if res != 'Y' and res != 'y':
65  print("Aborting")
66  exit(1)
67 
68  config = lms.NetworkInfo()
69  config.ip_address = args.new_ip_address
70  config.gateway = args.new_gateway
71  config.netmask = args.new_netmask
72  status = channel.set_network_config(config, args.interface)
73  if status != lms.Status.OK:
74  print("Cannot set configuration", lms.to_string(status))
75  exit(1)
76 
77 
78 if __name__ == '__main__':
79  parser = argparse.ArgumentParser("LibMultiSense change ip utility")
80  parser.add_argument("-a", "--current-ip_address", default="10.66.171.21", help="The current IPv4 address of the MultiSense.")
81  parser.add_argument("-A", "--new-ip_address", default="10.66.171.21", help="The new IPv4 address of the MultiSense.")
82  parser.add_argument("-G", "--new-gateway", default="10.66.171.1", help="The new IPv4 gateway of the MultiSense.")
83  parser.add_argument("-N", "--new-netmask", default="255.255.255.0", help="The new IPv4 netmask of the MultiSense.")
84  parser.add_argument("-b", "--interface", help="send broadcast packet to a specified network interface. "
85  "This resets the IP address to the new configured ip")
86  parser.add_argument("-y", "--disable-confirmation", action='store_true', help="Disable confirmation prompts")
87  main(parser.parse_args())
change_ip_utility.main
def main(args)
Definition: change_ip_utility.py:44
multisense::to_string
std::string to_string(const Status &status)
Convert a status object to a user readable string.
Definition: utilities.cc:137


multisense_lib
Author(s):
autogenerated on Thu Apr 17 2025 02:49:08