Hi I want to get all tcp/udp opening port status list on iphone by objective-c? like netstat on Linux, Do you know how to achieve it or it there any API can do that? Thanks.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
You can't run
netstat
on an iPhone (unless you jailbreak it), but you can do whatnetstat
does. Take a look at functionprotopr
in thenetstat
source code. I verified that you can callsysctlbyname
with"net.inet.tcp.pcblist"
as the name and get back a bunch of data. I didn't try to interpret the data likenetstat
does.Test case:
Output on my iPad 2 running iOS 5.0:
and lots more I have truncated.
Make sure you're initializing
len
to 0. Also, you can't just put the contents ofbuf
in anNSString
as if it were a C string. It's not. It's binary data that you have to interpret, likenetstat
does.Presumably you want to interpret the data. You need to read through the
protopr
function in thenetstat
source code, which I linked to above. The data structures used byprotopr
are declared in<netinet/in_pcb.h>
,<netinet/tcp_var.h>
, and other header files in/usr/include/netinet
. These header files are included in the iOS SDK (as of iOS 7.0 at least), so you can use them.To get the data obtained by the rob mayoff's answer readable you just need to take a look at the code of inet.c. In it, you have all you need to parse the data.
Take a look at my another answer in the question of Hisenberg: Network Activity Monitoring on iPhone
In my code, you can see in what part of the code the data is readable, that is when I add the values to the dictionary.