What is needed
Using scutil, I may get the list of Network services, including from virtual interfaces (e.g. VPN).
scutil
> list
Which provides:
...
subKey [82] = State:/Network/Service/3EEEA1D1-D35B-427E-BDE0-2025141B495C
subKey [83] = State:/Network/Service/3EEEA1D1-D35B-427E-BDE0-2025141B495C/IPv6
subKey [84] = State:/Network/Service/7B9ECA06-5F37-474A-88A9-CC4EE3638A0E/DHCP
subKey [85] = State:/Network/Service/7B9ECA06-5F37-474A-88A9-CC4EE3638A0E/DNS
subKey [86] = State:/Network/Service/7B9ECA06-5F37-474A-88A9-CC4EE3638A0E/IPv4
subKey [87] = State:/Network/Service/D987D3B3-5AF0-43C8-937E-86B0F8B9D59A
subKey [88] = State:/Network/Service/D987D3B3-5AF0-43C8-937E-86B0F8B9D59A/IPv6
subKey [89] = State:/Network/Service/com.sparklabs.Viscosity.utun10/DNS
subKey [90] = State:/Network/Service/com.sparklabs.Viscosity.utun10/IPv4
subKey [91] = State:/Network/Service/com.sparklabs.Viscosity.utun10/IPv6
You may see that first 82-88 are real interfaces, while the last 89-91 is a virtual interface (UTUN) which corresponds to a VPN of type OpenVPN. I need to retrieve this com.sparklabs.Viscosity.utun10 service name.
Getting services
Failing to get services of virtual interfaces
I am able to list all physical services with the following code:
auto prefs = SCPreferencesCreate(nullptr, CFSTR("test"), nullptr);
CFArrayRef services = SCNetworkServiceCopyAll(prefs);
const size_t num = CFArrayGetCount(services);
for (size_t i = 0; i< num; ++i)
{
NSLog(#"Service: %#", CFArrayGetValueAtIndex(services, i));
}
However the result does not include the UTUN service:
Service: <SCNetworkService 0x7fa2387078b0 [0x7fff84d43cf0]> {id = FDE22A30-76DA-4AE4-963F-FDE4769EAC91, prefs = 0x7fa23840a900}
Service: <SCNetworkService 0x7fa238706430 [0x7fff84d43cf0]> {id = 9EFF9EEA-EE7B-4D85-8DBD-291FA1A80FE5, prefs = 0x7fa23840a900}
Service: <SCNetworkService 0x7fa238706910 [0x7fff84d43cf0]> {id = 3BA8DFA7-C609-4746-A5B5-5A452F6AF44B, prefs = 0x7fa23840a900}
Service: <SCNetworkService 0x7fa238706140 [0x7fff84d43cf0]> {id = 7B9ECA06-5F37-474A-88A9-CC4EE3638A0E, prefs = 0x7fa23840a900}
Service: <SCNetworkService 0x7fa238705de0 [0x7fff84d43cf0]> {id = A14CD980-C388-4A5D-8DE5-493B62D78A60, prefs = 0x7fa23840a900}
Getting interfaces
Failing to get the service related to the interface
Interfaces, including virtual one are quite easy to retrieve:
SCDynamicStoreRef ds = SCDynamicStoreCreate(nullptr, CFSTR("test"), nullptr, nullptr);
const auto list = SCDynamicStoreCopyKeyList(ds, CFSTR("State:/Network/Interface"));
const size_t num = CFArrayGetCount(list);
for (size_t i = 0; i< num; ++i)
{
auto key = static_cast<CFStringRef>(CFArrayGetValueAtIndex(list, i));
auto value = static_cast<CFDictionaryRef>(SCDynamicStoreCopyValue(ds, key));
NSLog(#"%# = %#", key, value);
}
With the following result:
State:/Network/Interface = {
Interfaces = (
...
en0,
en1,
...
utun10
);
}
However, I am not able to get the service interface related to them, thus.
Question
How to list virtual network services?
Related questions
How to list all available patterns in a SCDynamicStorage?
Finding DNS server settings programmatically on Mac OS X
Related
I wrote the below code to add a generic password from my app. SecKeychainAddGenericPassword() adds the app as a trusted application in the keychain by design.
I want to remove my app from the list of trusted apps. I called SecKeychainItemSetAccess () to do that but I still see my app listed as a trusted app.
addgenericpassword(const std::string& service,const std::string& account,
const std::string& password) {
SecKeychainItemRef item_ref;
OSStatus status = SecKeychainAddGenericPassword(NULL,
service.length(),
service.data(),
account.length(),
account.data(),
password.length(),
password.data(),
&item_ref);
//Creating an secAccess object that has an empty trusted application list
//https://developer.apple.com/documentation/security/1393522-secaccesscreate?language=objc
CFArrayRef applicationList=CFArrayCreate (NULL,NULL,0,NULL);
SecAccessRef accessref;
CFStringRef description=CFStringCreateWithCString(NULL, "Generic description", kCFStringEncodingASCII);
status = SecAccessCreate(description,applicationList,&accessref);
//Set the access of a keychain item "item_ref".
status = SecKeychainItemSetAccess(item_ref,accessref);
CFRelease(item_ref);
CFRelease(accessref);
CFRelease(applicationList);
CFRelease(description);
return 0;
}
Update:
Changed description to match the service name. Still no luck
CFStringRef description=CFStringCreateWithCString(NULL, service.data(), kCFStringEncodingASCII);
I have been able to get the functionality I was looking for.I am not sure if this is the right method to do it though.
SecAccessRef accessref;
SecKeychainItemCopyAccess(item_ref, &accessref);
CFArrayRef aclList;
SecAccessCopyACLList(accessref, &aclList);
CFIndex count = CFArrayGetCount(aclList);
//Array with 0 Applications / Empty Array . Not the same as passing NULL
CFArrayRef zero_applications = CFArrayCreate(NULL, NULL, 0, NULL);
for (int i = 0; i < count; i++) {
SecACLRef acl = (SecACLRef) CFArrayGetValueAtIndex(aclList, i);
CFArrayRef applicationList;
CFStringRef description;
CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR promptSelector;
SecACLCopySimpleContents(acl, &applicationList, &description,
&promptSelector);
if (applicationList == NULL) {
continue;
}
CFIndex appCount = CFArrayGetCount(applicationList);
for (int j = 0; j < appCount; j++) {
status= SecACLSetContents(acl, zero_applications, description, 1);
break;
}
CFRelease(applicationList);
CFRelease(description);
}
// Set the modified copy to the item now
status = SecKeychainItemSetAccess(item_ref, accessref);
I want to get a snapshot of the process info in the os x system.
The 'NSProcessInfo' can only get info of the calling process.
The ps cmd can be one solution, but i'd like a c or objective-c program.
Here's an example using using libproc.h to iterate over all the processes on the system and determine how many of them belong to the effective user of the process. You can easily modify this for your needs.
- (NSUInteger)maxSystemProcs
{
int32_t maxproc;
size_t len = sizeof(maxproc);
sysctlbyname("kern.maxproc", &maxproc, &len, NULL, 0);
return (NSUInteger)maxproc;
}
- (NSUInteger)runningUserProcs
{
NSUInteger maxSystemProcs = self.maxSystemProcs;
pid_t * const pids = calloc(maxSystemProcs, sizeof(pid_t));
NSAssert(pids, #"Memory allocation failure.");
const int pidcount = proc_listallpids(pids, (int)(maxSystemProcs * sizeof(pid_t)));
NSUInteger userPids = 0;
uid_t uid = geteuid();
for (int *pidp = pids; *pidp; pidp++) {
struct proc_bsdshortinfo bsdshortinfo;
int writtenSize;
writtenSize = proc_pidinfo(*pidp, PROC_PIDT_SHORTBSDINFO, 0, &bsdshortinfo, sizeof(bsdshortinfo));
if (writtenSize != (int)sizeof(bsdshortinfo)) {
continue;
}
if (bsdshortinfo.pbsi_uid == uid) {
userPids++;
}
}
free(pids);
return (NSUInteger)userPids;
}
I am implementing WCF service to implement online Net banking using github jaymedavis/stripe.net code (https://github.com/jaymedavis/stripe.net#charges).
here is my code for creating customer, Bank Account and Bank Account service for verifying Bank account and Creating charges.
Code:
//1. Create Customer
var myCustomer = new StripeCustomerCreateOptions();
myCustomer.Email = "pork#email.com";
myCustomer.Description = "Johnny Tenderloin (pork#email.com)";
//myCustomer.SourceToken = *token*;
//myCustomer.PlanId = *planId*; // only if you have a plan
//myCustomer.TaxPercent = 20; // only if you are passing a plan, this tax percent will be added to the price.
//myCustomer.Coupon = *couponId*; // only if you have a coupon
//myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1); // when the customers trial ends (overrides the plan if applicable)
//myCustomer.Quantity = 1; // optional, defaults to 1
//2. Create Customer Service
var customerService = new StripeCustomerService(StripeApiKey);
StripeCustomer stripeCustomer = customerService.Create(myCustomer);
//3. Create bankAccount
var myBankAccount = new BankAccountCreateOptions
{
SourceBankAccount = new SourceBankAccount()
{
AccountNumber = "000123456789", //,
Country = "US",
Currency = "usd",
AccountHolderName = "Frank", //"Johnny Tenderloin",
AccountHolderType = BankAccountHolderType.Individual,
RoutingNumber = "110000000", //"021000021",
Metadata = new Dictionary<string, string>
{
{ "Name", "Ray Barone" },
{ "OftenSays", "Thatttttt's right" }
}
}
};
//4. Create bankAccount Service
var bankAccountService = new BankAccountService(StripeApiKey);
CustomerBankAccount bankAccount = bankAccountService.Create(stripeCustomer.Id, myBankAccount);
BankAccountVerifyOptions bankAccountVerifyOpt = new BankAccountVerifyOptions();
bankAccountVerifyOpt.AmountOne = 32;
bankAccountVerifyOpt.AmountTwo = 45;
//
//5. Verify bankAccount or service
bankAccount = bankAccountService.Verify(stripeCustomer.Id, bankAccount.Id, bankAccountVerifyOpt );
//6. Create Charge
var myChargeBank = new StripeChargeCreateOptions();
// amount = Returnamount.amount;
myChargeBank.Amount = int.Parse("250") * 100;
myChargeBank.Currency = "usd";
myChargeBank.CustomerId = stripeCustomer.Id;
myChargeBank.Capture = true;
StripeCharge stripeCharge = null;
stripeCharge = new StripeCharge();
var chargeService = new StripeChargeService(StripeApiKey);
stripeCharge = chargeService.Create(myChargeBank);
if (stripeCharge.Status.ToLower() == "succeeded" & stripeCharge.Paid == true) {
} else {
}
In this code, I am getting:
Stripe Exception for Verify method (bankAccountService.Verify(stripeCustomer.Id, bankAccount.Id, bankAccountVerifyOpt );)
Exception is Received unknown parameter: amounts.
on "https://github.com/jaymedavis/stripe.net#charges" implementation for 'Verify a bank account' is missing so Please help me to solve this problem so that bank account get verify successfully.
I had the same issue and I did 2 things:
1) On stripe.com, I went to my account API settings and updated them to use the lasted API.
2) I updated the Stripe.net Nuget package
After that everything worked perfectly.
I have implemented the multiparty video chat (audio and video enabled) and it is working fine. How can I figure out which peer is speaking and highlight a green icon besides that user.
The onStreamAdded gets called only when a new stream is added but how do I track
who is speaking currently.
Regards
Raghav
Take a look at the Otalk hark github project.
Hark is a tiny browser/commonJS module that listens to an audio stream, and emits events indicating whether the user is speaking or not. Hark uses the webaudio API to FFT (get the power of) the audio in the audio stream. If the power is above a threshold, it's determined to be speech.
https://github.com/otalk/hark
Hi you can use below logic to show active user on page.
Typescript:-
class AudioListenerBase {
private audio_progress: number = 0;
private audioContext = new AudioContext();
private analyser: AnalyserNode;
private microphone: MediaStreamAudioSourceNode;
private javascriptNode: ScriptProcessorNode;
public remotesElement: any;
constructor(
private zone: NgZone,
private cd: ChangeDetectorRef,
private stream: any,
private audioProgressCallBack: any
) {
this.analyser = this.audioContext.createAnalyser();
this.microphone = this.audioContext.createMediaStreamSource(stream);
this.javascriptNode = this.audioContext.createScriptProcessor(2048, 1, 1);
this.analyser.smoothingTimeConstant = 0.8;
this.analyser.fftSize = 1024;
this.microphone.connect(this.analyser);
this.analyser.connect(this.javascriptNode);
this.javascriptNode.connect(this.audioContext.destination);
this.javascriptNode.onaudioprocess = (() => {
var array = new Uint8Array(this.analyser.frequencyBinCount);
this.analyser.getByteFrequencyData(array);
var values = 0;
var length = array.length;
for (var i = 0; i < length; i++) {
values += (array[i]);
}
var average = (values / length) * 10;
if (this.audio_progress - average > 5 || average - this.audio_progress > 5)
this.zone.run(() => {
this.audio_progress = average;
this.cd.detectChanges();
audioProgressCallBack(this.audio_progress, this.remotesElement)
});
});
return this;
}
}
usage on component :-
this.myAudioListener = new AudioListenerBase(this.zone, this.changeDetectorRef, stream, (val, remotesElement) => {
this.audio_progress = val;
});
On component Html:
<div> <p>{{item.username}}</p> <p style="font-size:10px">{{item.audio_progress>20?'speaking..':''}}</p></div>
I need some help, maybe someone faced a similar task.
I want to find all workflows with status "Error ocured" using SharePoint 2010 web services.
And I want to know is this task possible?
Thanks.
With CAML you can query using web services.
Use method GetListItems and CAML query with WorkflowStatus = 3 (Error occurred).
public XmlNode _nodes;
string _ListID = "";
string _ViewID = "";
XmlDocumento _xmlDoc = new System.Xml.XmlDocument();
XmlElement _query = _xmlDoc.CreateElement("Query");
XmlElement _queryOptions = _xmlDoc.CreateElement("QueryOptions");
XmlElement _viewFields = _xmlDoc.CreateElement("ViewFields");
_query.InnerXML = #"
<Where>
<Eq>
<FieldRef Name='WorkflowNameColumn' />
<Value Type='WorkflowStatus'>3</Value>
</Eq>
</Where>";
_queryOptions.InnerXml = "<QueryOptions> <IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>";
_viewFields.InnerXml = "";
// SharepointListWS is the name i use in Web References
SharepointListsWS.Lists _lst = new SharepointListsWS.Lists();
_nodes = _lst.GetListItems(_listID, _ViewID, _query, _viewFields, "300", _queryOptions, null);
foreach (XmlNode node in _nodes) {
if (node.Name.ToLower() == "rs:data") {
for (int i = 0; i < node.ChildNodes.Count; i++) {
if (node.ChildNodes[i].Name.ToLower() == "z:row") {
// you can debug here
XmlNode AllNodes = node.ChildNodes[i];
// Find at Attributes
for (int a = 0;a < AllNodes.Attributes.Count; a++) {
string field = AllNodes.Attributes[a].Value.Trim();
string name = AllNodes.Attributes[a].Name;
string colName = XmlConvert.DecodeName(name).ToLower().Replace("ows_", "");
}
}
}
}
}
Status list can be found here.