How to delete an IP address when you don't have the net table entry context - c++

The DeleteIPAddress function can be used to remove an IP address which was added at an earlier time using AddIPAddress. You obtain the net table entry context when you add the address and pass it as a parameter to DeleteIPAddress.
In my case, there must be a reboot between the time that the IP address is added and when we want to remove it. The address is persistent and remains after the reboot but we no longer have the net table entry context so DeleteIPAddress fails. How else can I remove this IP address?
I'm working with C++ on Windows 7.
Thanks.

found the following at ms; GetAdaptersInfo should be what you need
DeleteIPAddress fails in Windows XP when deleting an IP address not added using AddIPAddress
In Windows 7, I can delete an IP address using DeleteIPAddress() even though I did not add it using AddIPAddress(). I can do this by getting the NTEContext of the desired IP address of a specific network adapter via GetAdaptersInfo().
This does not seem to work on Windows XP SP3 Professional. DeleteIPAddress() returns an error ERROR_GEN_FAILURE "A device attached to the system is not functioning.". All other preceding and succeeding calls to IP Helper functions succeeds so there is nothing wrong with my device.

Related

How to check dates,time,and number of times access to a certain IP was granted C/c++

i am working on a digital forensics case study and am attempting to write a c/c++ program on how to check the date and time or dates and specific times an IP address was given access to by this program. I am wondering on what would be the best way to implement this into my program. i have already checked to see if the string entered is a valid ipv4 or ipv6 address and was wondering if there is any functions or lib's that can make this process much easier.
Thanks
If I understand you correctly, you are trying to write a C++ program that takes an IP address as an input, keeps checking to see if that particular IP address is accessible by you (your program).
You could try to monitor changes in firewall (bigger scope) 2)
You could run a command line tool like ping and parser the output 3)
You could do C/C++ coding to do the pinging yourself like suggested
in this post
You could try to keep connecting, at brief intervals, to the IPaddress at a particular TCP/UDP port.

WMI methods for Hyper-V network management is failing on Windows 2012

I have been trying to use WMI classes (using C++) to manage Virtual Switches in Hyperv like Creation,Deletion, Attach a Virtual Network to a VM etc. I was able to do everything perfectly on Windows 2008 R2. But none of them are working fine on Windows 2012.
For example when I create an externalnetwork I call a method called CreateSwitchPort on the object of the class Msvm_VirtualSwitchManagementService. It's working on 2k8R2 but fails with out parameter return value as 32768 which means failure. Can anyone point out why does the method return an error? How to debug the issue? Are there any permissions I should be giving. Any help in the regard is highly appreciated.
--Ramakrishna.
Hyper-V 2012 supports the previous WMI API, and I have successfully used it. Hyper-V 2012 introduces a v2 API, but this is irrelevant to you.
CreateSwitchPort is a very straightforward call. Here is an example in Python that is quite readable. The Python call returns a tuple that the [out] parameters are added to.
#Create a port on the vswitch.
(new_port, ret_val) = switch_svc.CreateSwitchPort(
Name=str(uuid.uuid4()),
FriendlyName=vm_name,
ScopeOfResidence="",
VirtualSwitch=extswitch.path_())
Check that the VirtualSwitch parameter is valid. I use a WMI query shown below to get this object. It fails if the VirtualSwitch is not connected to an external NIC. Is your query successful?
return self._conn.Msvm_ExternalEthernetPort(IsBound='TRUE')[0]\
.associators(wmi_result_class='Msvm_SwitchLANEndpoint')[0]\
.associators(wmi_result_class='Msvm_SwitchPort')[0]\
.associators(wmi_result_class='Msvm_VirtualSwitch')[0]
Next, look to see if the name Name parameter needs to be unique. If you use a static name, the call might fail because of a naming conflict.
If none of this helps, then start inspecting the Hyper-V WMI objects in realtime. You can use Python and the WMI bindings for Python by Tim Golden.

How to get MAC address and channel info with Native Wifi API C++

I have this:
WLAN_AVAILABLE_NETWORK_LIST *wlanNetworkList = (WLAN_AVAILABLE_NETWORK_LIST*)WlanAllocateMemory(sizeof(WLAN_AVAILABLE_NETWORK_LIST));
and I get info about networks with WlanGetAvailableNetworkList() function.
But in this info there aren't mac address or channel.
How to get that?
I think the information you're looking for is in the WLAN_BSS_ENTRY structure.
As there might me more than one access points for a network, it makes at least sense to me that there is not a single MAC address for a network (also consider ad-hoc networks) and therefore, the MAC address is not part of the properties of the network (is no data member of the WLAN_AVAILABLE_NETWORK structure).
Using WlanGetNetworkBssList (msdn library entry) you can get a list of BSS entries for a specific network (by passing the SSID) or for all networks of a wireless LAN interface. Note this function queries the access point:
The list of information returned for each wireless network also contains a list of information elements returned by each access point for an infrastructure BSS network or a network peer for an independent BSS network (ad hoc network).
By the way: I think you don't need to allocate a buffer for the WLAN_AVAILABLE_NETWORK_LIST structure with WlanAllocateMemory. MSDN:
The buffer for the WLAN_AVAILABLE_NETWORK_LIST returned is allocated by the WlanGetAvailableNetworkList function if the call succeeds.
Yet, you have to free the memory the function has allocated for the list via WlanFreeMemory.
See also the example in msdn library (bottom of that page).
Edit: the example is a bit confusing, there's a variable called pBssList which is of type PWLAN_AVAIBLE_NETWORK_LIST and not PWLAN_BSS_LIST as the name suggests.
maybe you will try first use WlanScan.
I try write WlanApi in assembly, goasm.
I use WlanGetNetworkBssList.
Everything Work, in return i get 6 bytes of mac but only first 3 is the same like Mac my router. I don't understand why. Maybe I'm write wrong sruct in WlanApi.h
I'm still studing ASM
WlanApi.h
MyCode

Is it possible to "assert" in Puppet?

Is there a way to assert that a variable (or more specifically, a fact) in puppet has a particular value, and to abort the installation if it doesn't?
For background, here is the situation:
In most cases I can refer to hostnames, but sometimes I need to use an IP address. For example, our log collector host needs to open a port in the firewall for several specific machines (and not a whole subnet). I need to use IP addresses to open a hole in the firewall. Since the IP addresses of machines don't change, I was planning on encoding the IP address as part of the configuration, but I'd like to check on the individual hosts that the actual IP address matches the one in its configuration and fail if it doesn't. Is that possible?
I believe something like this would work:
if $ipaddress != $expectedipaddress {
fail("IP mismatch")
}
The fail() function causes a parse failure. Wrapping it in a conditional should get the assert behavior you want.
I haven't tested this specific usage, but if parsing fails a new catalog isn't compiled and the client doesn't get anything.

Changing the system time zone succeeds once and then no longer changes

I'm using the WinAPI to set the time zone on a Windows XP SP3 box. I'm reading the time zone information from the HKLM\Software\Microsoft\WindowsNT\Time Zones\<time zone name> key and then setting the time zone to the specified time zone.
I enumerate the keys under the Time Zones key, grab the TZI value and stuff it into a TIME_ZONE_INFORMATION struct to be passed to SetTimeZoneInformation. All seems to work on the first pass. The time zone changes, no error is returned.
The second time I perform this operation (same user, new session, on login before userinit) the call succeeds but the system does not reflect the time zone change. Neither the clock nor time stamps on files are updated to the new time zone. When I navigate to:
HKLM\System\CurrentControlSet\Control\TimeZoneInformation my new time zone information is present.
A couple strange things are happening when I'm setting my time zone:
Also when I parse the TZI binary value from the registry to store in my TIME_ZONE_INFORMATION struct I'm noticing the struct has the DaylightDate.wDay and StandardDate.wDay field always set to 0
I tried to call GetTimeZoneInformation right after I call SetTimeZoneInformation but the call fails with a 1300 error (Not all privileges or groups referenced are assigned to the caller. )
I'm also making sure to send a WM_BROADCAST message so Explorer knows whats going on.
Think it's the parsing of the byte array to the TIME_ZONE_INFORMATION struct? Or am I missing some thing else important?
EDIT:
Found a document stating why this is happening: here. Privilege was introduced in Vista...thanks MSDN docs...
Per the Microsoft documentation
I'm enabling the SE_TIME_ZONE_NAME
privilege for the current processes
token. But when I attempt to call
LookupPriviledgeValue for
SE_TIME_ZONE_NAME I get a 1313
error (A specified privilege does
not exist. ).
Try to use LsaAddAccountRights instead of LookupPrivilegeValue and AdjustTokenPrivileges to set SE_TIME_ZONE_NAME. See also this topic.
After messing with this for awhile I've fixed the issue but I'm not quite sure what step fixed it. I added an extra clause to check the OS to verify whether or not to adjust the process token to enable the SE_TIME_ZONE_NAME. It now only does this on post-XP OS's.
I also changed how the TZI registry value was stored into my struct. I realized that on the TIME_ZONE_INFORMATION MSDN document is contained the struct that is used for the registry verison (REG_TZI_FORMAT). Simply reading the binary value straight into the struct eliminated a bit of code.
I also guaranteed that BOTH DaylightName and StandardName were populated.
Finally I called a RegFlushKey(HKEY_LOCAL_MACHINE) right after the SetTimeZoneInformation call. After taking these steps the time zone is changing as expected.