Relay Affiliation Using Hyper-v Default Switch

I have the following code that gets the location name based on the IP address from a file with the IP addresses and associated location names. It is in the following format.

10.248.224.0/20 “Location Name” City State Country Region Address client

I only use IP and location name. I am not sure how to use City, State, etc.

Anyway I have a couple of systems with Hyper-V. Those systems are not getting the correct location name because the address of the Default Switch for Hyper-V is being used to match the location. The address of the default switch is 172.28.64.1. I don’t think this address should be used at all, but I don’t know how to exclude it within the existing code.

setting "_BESClient_Register_Affiliation_SeekList"="{/* If No Record Found, then use FailOvers. However, this could also be used to handle prioritization of subnets */ ( if (number of elements of it = 0) then ("HeadRelay;*") else concatenation ";" of (elements of it)) of set of /* Prepare Affiliation String */ ( preceding text of last ";" of ( (if(exists item 0 of it AND item 0 of it != "" ) then (item 0 of it & ";") else "") /* & (if(exists item 2 of it AND item 2 of it != "" AND item 6 of it is contained by "state,country,region,all relays" ) then (item 2 of it & ";") else "") & (if(exists item 3 of it AND item 3 of it != "" AND item 6 of it is contained by "country,region,all relays") then (item 3 of it & ";") else "") & (if(exists item 4 of it AND item 4 of it != "" AND item 6 of it is contained by "region,all relays") then (item 4 of it & ";") else "") & (if(exists item 6 of it AND item 6 of it = "headend") then ("HeadRelay" & ";") else "") */ )) of /* Disect Line From SubnetMap.txt */ ( /* Location Code - item 0 */ preceding text of first "%09" of it, /* City Code - item 1 */ preceding text of first "%09" of following text of first "%09" of it, /* State - item 2 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of it, /* Country - item 3 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of it, /* Region - item 4 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09"of following text of first "%09" of it, /* Address - item 5 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of it, /* FailOverFlag item 6 */ following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of it ) of /* Remove Duplicates */ (elements of set of it) of /* Compare Subnets Of Network Adapters To SubnetMap.txt */ ( following texts of firsts "||" of unique values of ( (bit (preceding text of first "%09" of it as integer)) of item 2 of it as string & "||" & following text of first "%09" of item 2 of it) of ( ( first (following text of first "/" of it as integer) of item 0 of it, first (following text of first "/" of it as integer) of item 1 of it, item 2 of it ) of ( (item 0 of it & "/" & following text of first "/" of preceding text of first "%09" of item 1 of it) , ( ( concatenation of (last 8 of ("00000000" & (it as integer) as bits as string)) of substrings separated by "." of it) of preceding text of first "/" of item 1 of it & "/" & following text of first "/" of preceding text of first "%09" of item 1 of it ) , (following text of first "/" of item 1 of it) ) of ( ( ( ( concatenations of (last 8 of ("00000000" & (it as integer) as bits as string)) of substrings separated by "." of it) ) of (( ( addresses whose (it as string != "0.0.0.0") of ip interfaces whose (loopback of it = false) of network ) as string ) ) ) , ( lines whose ( (it = regex "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+/[[:digit:]]+[[:blank:]].*[[:blank:]].*") AND (it contains "%09") ) of (file "SubnetMap.txt" of client folder of site whose (name of it = "RelayAffiliation")) ) ) ) whose (item 0 of it = item 1 of it) ) & ";HeadRelay"}" on "{now}" for client

Near the end of the query I think the addresses whose() filter could be used. Try modifying

addresses whose (it as string != “0.0.0.0”) of ip interfaces whose (loopback of it = false) of network ) as string

to

addresses whose (it as string != “0.0.0.0” and it as string does not start with "172.28.64.") of ip interfaces whose (loopback of it = false) of network ) as string

It also needs to be a virtual adapter address.

Ok, how is that determined? By the gateway address, by the MAC address, by the interface name, or something else?

The adapter with the currently active IP address that is pingable on the network.

I may not have completely understood this before, I’m still trying to piece it together.

So you have some Hyper-V Host-Only networks defined, in the 172.28.64.0 range.

  1. Is that 172.28.64.0 subnet also matching an entry in your subnet list file, so you’re getting an incorrect match?

  2. Is your mismatch affecting only the Hyper-V host itself, or also the VMs running under Hyper-V?

  3. On the Hyper-V host, does ‘ipconfig’ show one of the addresses as 172.28.64.1, or does it show some other address on the virtual switch?

I don’t think there’s a way on the machine itself to know which of its addresses is “pingable” from elsewhere on the network; I’m considering a path that checks for interfaces with a default gateway defined (there should only be one of those at least)

To get just the IP addresses of interfaces with a default gateway, I’d change that same part of the query to

(addresses whose (it as string != "0.0.0.0") of ipv4 interfaces whose (loopback of it = false) of adapters whose (exists gateway of it) of network ) as string

I don’t have the sample file to test with and it looks like I’d have to do quite a bit of setup to get it exactly but I think you might be able to substitute this in as

/* If No Record Found, then use FailOvers. However, this could also be used to handle prioritization of subnets */ ( if (number of elements of it = 0) then ("HeadRelay;*") else concatenation ";" of (elements of it)) of set of /* Prepare Affiliation String */ ( preceding text of last ";" of ( (if(exists item 0 of it AND item 0 of it != "" ) then (item 0 of it & ";") else "") /* & (if(exists item 2 of it AND item 2 of it != "" AND item 6 of it is contained by "state,country,region,all relays" ) then (item 2 of it & ";") else "") & (if(exists item 3 of it AND item 3 of it != "" AND item 6 of it is contained by "country,region,all relays") then (item 3 of it & ";") else "") & (if(exists item 4 of it AND item 4 of it != "" AND item 6 of it is contained by "region,all relays") then (item 4 of it & ";") else "") & (if(exists item 6 of it AND item 6 of it = "headend") then ("HeadRelay" & ";") else "") */ )) of /* Disect Line From SubnetMap.txt */ ( /* Location Code - item 0 */ preceding text of first "%09" of it, /* City Code - item 1 */ preceding text of first "%09" of following text of first "%09" of it, /* State - item 2 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of it, /* Country - item 3 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of it, /* Region - item 4 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09"of following text of first "%09" of it, /* Address - item 5 */ preceding text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of it, /* FailOverFlag item 6 */ following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of following text of first "%09" of it ) of /* Remove Duplicates */ (elements of set of it) of /* Compare Subnets Of Network Adapters To SubnetMap.txt */ ( following texts of firsts "||" of unique values of ( (bit (preceding text of first "%09" of it as integer)) of item 2 of it as string & "||" & following text of first "%09" of item 2 of it) of ( ( first (following text of first "/" of it as integer) of item 0 of it, first (following text of first "/" of it as integer) of item 1 of it, item 2 of it ) of ( (item 0 of it & "/" & following text of first "/" of preceding text of first "%09" of item 1 of it) , ( ( concatenation of (last 8 of ("00000000" & (it as integer) as bits as string)) of substrings separated by "." of it) of preceding text of first "/" of item 1 of it & "/" & following text of first "/" of preceding text of first "%09" of item 1 of it ) , (following text of first "/" of item 1 of it) ) of ( ( ( ( concatenations of (last 8 of ("00000000" & (it as integer) as bits as string)) of substrings separated by "." of it) ) of (( (addresses whose (it as string != "0.0.0.0") of ipv4 interfaces whose (loopback of it = false) of adapters whose (exists gateway of it) of network ) as string ) ) ) , ( lines whose ( (it = regex "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+/[[:digit:]]+[[:blank:]].*[[:blank:]].*") AND (it contains "%09") ) of (file "SubnetMap.txt" of client folder of site whose (name of it = "RelayAffiliation")) ) ) ) whose (item 0 of it = item 1 of it) ) & ";HeadRelay"

1 Like

Thank you very much! That seems to be the answer.

1 Like