Mac app to switch between /etc/hosts files, how to allow access?
In order to modify files like /etc/hosts
which are writable only by root, you will need to use a privileged helper tool, install it using SMJobBless()
, and communicate with it via XPC.
Apple's EvenBetterAuthorizationSample sample code demonstrates the recommended way to do this, along with providing a small sample library that you can use. It is in Objective-C, but Objective-C code is not difficult to integrate into a Swift project. (One of these days, I'll publish my own Swift-native version of this, but it currently needs cleaning up before I'll be proud of the source.)
Does hosts file exist on the iPhone? How to change it?
This doesn't directly answer your question, but it does solve your problem...
What make of router do you have? Your router firmware may allow you to set DNS records for your local network. This is what I do with the Tomato firmware
How to access and modify a SSH file on mac?
Start Terminal and create the ~/.ssh
directory if it doesn't exist:
mkdir -p ~/.ssh
Now go into the directory:
cd ~/.ssh
Now open the file config
with the default editor:
open -t config
If it says that file doesn't exist, create it with:
touch config
and try opening again:
open -t config
When you edit the file, make sure it is "Plain Text" using the menu at the top of the screen and clicking Format->Make Plain Text.
Set the permissions as instructed in your tutorial.
Can I edit an iPad's host file?
No. Apps can only modify files within the documents directory, within their own sandbox. This is for security, and ease of installing/uninstalling. So you could only do this on a jailbroken device.
How to edit /etc/hosts file in Android Studio emulator running in nougat?
I was able to edit the /etc/hosts file by launching the emulator with -writable-system and remounting the emulator using adb remount. After that the hosts file inside the emulator is editable. I tried pushing/replacing the file and succeeded.
SwiftUI: How to access terminal with MacOS app?
Try disabling the App Sandbox. It should work then.
EDIT:
let executableURL = URL(fileURLWithPath: "/bin/zsh")
self.isRunning = true
do {
try Process.run(executableURL,
// Replace userpassword with the user's password and yourline with the line you want to append to the file. (If you really want to use nano, you can replace echo... >> ... with nano /private/etc/hosts)
arguments: ["-c", "echo password | sudo -S -- sh -c \"echo test >> /etc/hosts\""],
terminationHandler: { _ in self.isRunning = false })
} catch {
print(error)
}
How do I set up the hosts file for multiple domains/hosts with the same IP?
I got this resolved thanks to Google and the collaborators, @jvilhena and @DRC. Here's how I did it:
If you are using Windows and XAMPP as in my case the first step is to set up the 'hosts' file. If you are using Windows it's likely that you will find it in C:\Windows\System32\drivers\etc\hosts. You can use any text editor to edit it.
You can set up as many host names as you like all pointing to your localhost, with the IP, 127.0.0.1.
For example:
127.0.0.1 local.project1
127.0.0.1 local.project2
127.0.0.1 youcanuseany.name.here
The second step was to deal with the Apache file httpd-vhosts.conf. Again, I'm using Windows and XAMPP. It's likely this file will be in C:\xampp\apache\conf\extra\httpd-vhosts.conf.
You don't have to but I like to keep my project folders in my htdocs folder @ C:\xampp\htdocs.
For each project that you create a "host name" for, you should add the following to your httpd-vhosts.conf file:
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs\projectx"
ServerName youcanuseany.name.here
<Directory "C:\xampp\htdocs\projectx">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
One more example just for the sake of it :)
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs\project1"
ServerName local.project1
<Directory "C:\xampp\htdocs\project1">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now you can type local.project1
and youcanuseany.name.here
in your browser and it should open your project as if you were typing localhost/project1
and localhost/projectX
. I hope this helps.
iPhone: add entry to /etc/hosts without jailbreaking
Set up a real DNS entry, either by setting up a local DNS server on your wireless network, or by using a dynamic DNS service, or by adding an A record to a domain you control DNS for.
Related Topics
Convert String to Nsdate in Swift
How to Customize the Font and Appearance of a Uialertcontroller in the New Xcode W/ iOS8
Display Table View When Searchbar (From Searchcontroller) Begin Edited Swift
Using Codable to Encode/Decode from Strings to Ints with a Function in Between
Moving Skspritenode to Location of the Touch
Type a Requires That Type B Be a Class Type Swift 4
Setting Nsunderlinestyle Causes Unrecogognized Selector Exception
How to Properly Check If Non-Optional Return Value Is Valid
How to Delete Item from Collection View
Swift 2: Invalid Conversion from Throwing Function of Type to Non-Throwing Function
How to Get Core Data Entity by It's Objectid
What's Wrong with My #If Target_Os_Simulator Code for Realm Path Definition
Swift - Kvo - Change.Newvalue and Change.Oldvalue Are Nil
Ios-Charts Set Maximum Visible X Axis Values
Swiftui Pick a Value from a List with Ontap Gesture
Unit Testing Wknavigationdelegate Functions
Swift: Uploading Image to Firebase Cloud Storage When User Closes App
Difficulties to Assign Default Value to a Parameter of a Function