linux - How to determine the subnet mask and network interface card from remote SSH login? -


in separate question (link below), suggested obtain network interface card number , subnet mask remote ssh login, rather prompting user it. have ip address of remote host. need obtain subnet mask determine if remote , local host on same subnet, , interface card number set , configure virtual ip aliasing purposes.

could suggest how might able parse out necessary information , return shell script initiates remote ssh connection? target hosts have linux or aix operating system. familiar netstat function, i'm not sure if parsing information valid, or if there better way need work both linux , aix operating systems.

thanks can provide!

how return shell 'read' command passed in expect script?

--update--

aix ifconfig -a:

$ ifconfig -a en0: flags=1e080863,480<up,broadcast,notrailers,running,simplex,multicast,groupr t,64bit,checksum_offload(active),chain>         inet 10.105.65.131 netmask 0xffff0000 broadcast 10.105.255.255          tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1 lo0: flags=e08084b,c0<up,broadcast,loopback,running,simplex,multicast,grouprt,64 bit,largesend,chain>         inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255         inet6 ::1%1/0          tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1 

aix netstat -rn:

$ netstat -rn routing tables destination        gateway           flags   refs     use  if   exp  groups  route tree protocol family 2 (internet): default            10.105.65.1       ug       31  39412125 en0      -      - 10.105.0.0         10.105.65.131     uhsb      0         0 en0      -      -   = > 10.105/16          10.105.65.131     u       219 985607244 en0      -      - 10.105.65.131      127.0.0.1         ughs      5   1326738 lo0      -      - 10.105.255.255     10.105.65.131     uhsb      3   6926640 en0      -      - 127/8              127.0.0.1         u        36  11962928 lo0      -      -  route tree protocol family 24 (internet v6): ::1%1              ::1%1             uh        1    393270 lo0      -      - 

i tried route get , doesn't work on aix box tell me route. thing can work netstat -rn. i'm not sure if there command similar ip route work.

the linux boxes support both ip , ifconfig.

i not sure when there multiple network interface cards, not know 1 should used when setting virtual ip.

the linux setup more concerned with, adding in aix support software installation script later , can more research on then.

for linux, might (using bash extensions, invoked using #!/bin/bash shebang, or piping script on stdin interpreter invoked ssh "$hostname" bash <<'eof'):

internet_address=8.8.8.8 # read data nic used route here dev_re='dev ([^[:space:]]+)($|[[:space:]])' read default_route < <(ip -o route "$internet_address") [[ $default_route =~ $dev_re ]] && devname=${bash_rematch[1]}  ifs=$'\n' read -r -d '' -a addresses < \   <(netstat -rn |      awk -v dev="$devname" '$8 == dev && ($2 == "0.0.0.0" || $2 == "default") { print $1 }')  # emit output printf '%s\n' "$dev_re" "${addresses[@]}" 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -