於是乎...就是用 nc 指令來達成:
$ nc -z -w 3 remote_server 3306 && echo "OK"
其中 -w timeout 機制。
$ nc -z -w 3 remote_server 3306 && echo "OK"
#include <netdb.h>
#include <arpa/inet.h>
- (NSString*)hostnameToIPAddress:(NSString*)hostname
{
struct hostent *remoteHostEnt = gethostbyname([hostname UTF8String]);
struct in_addr *remoteInAddr = (struct in_addr *) remoteHostEnt->h_addr_list[0];
return [NSString stringWithUTF8String:inet_ntoa(*remoteInAddr)];
}
NSLog(@"IP: %@", [self hostnameToIPAddress:@"tw.yahoo.com"]);
NSLog(@"IP: %@", [self hostnameToIPAddress:@"tw.yahoo.com"]);
NSLog(@"IP: %@", [self hostnameToIPAddress:@"tw.yahoo.com"]);
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
@IBOutlet var button : UIButton
@IBAction func myClick(sender : AnyObject) {
println("Click")
button.setTitle("change", forState: UIControlState.Normal);
}
import UIKit
class MyTableViewController: UITableViewController {
var dataList = String[]()
override func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
return 1
}
override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
return dataList.count
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.text = dataList[indexPath.row]
return cell
}
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if segue.identifier.compare("showTable") == 0 {
if segue.destinationViewController.isKindOfClass(MyTableViewController) {
// Type 'AnyObject!' cannot be implicitly downcast to 'UIViewController'
// var vc:UIViewController = segue.destinationViewController
var tvc:MyTableViewController = segue.destinationViewController as MyTableViewController
tvc.dataList.append("Hello")
tvc.dataList.append("World")
}
}
}
<Directory /data/path>
AuthType Basic
AuthName "Password Required"
AuthUserFile /path/auth_pass
Order allow,deny
Allow from localhost
# Allow from DeviceIP
Satisfy any
</Directory>
$ wget -O /dev/null http://localhost/service/api
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:443... connected.
WARNING: no certificate subject alternative name matches
requested host name ‘localhost’.
HTTP request sent, awaiting response... 401 Unauthorized
Username/Password Authentication Failed.
iptables --table nat --append POSTROUTING --jump MASQUERADE